6

I am trying to create a swift module (Cocoa Touch Framework) with reusable code inside the environment set up by cocoa pods which includes third party libraries written in Objective-C (namely here Restkit). Unfortunately I am not able to use Restkit in the module I create.

Here's what I did to create the module:

  1. File -> New target: Cocoa Touch Framework, Language: Swift, Project: MyProject, Embed in Application: MyProject

  2. In the "Info" tab of the project settings in the "Configurations" section I define the Pods.debug and Pods.release xcconfig file for my newly created target.

  3. In the header file, which Xcode automatically created for me, networkModule.h, I add the following line:

    #import <RestKit/RestKit.h>

Result: When trying to compile I get the error "include of non-modular header inside framework module 'networkModule'"

I have set the flag for "Allow Non-modular Includes in Framework Modules" to YES in the build settings for the Project Target and the Module/Framework target.

I went to the Cocoa pod project and have tried setting the visibility of the RestKit.h Header file to "Public" in the target membership (which of course is not a good solution to mess with the cocoa pods environment)

I am not able to compile. I still get the same error.

Is it possible in the first place to create a Cocoa Touch Framework with dependencies to a cocoa pod managed framework?

Btw. My first idea of creating a private cocoa pod didn't work out as well, as it doesn't seem to be supported, although I am using the prerelease of cocoa pods 0.36 with support for swift.

7
  • This is a duplicate of stackoverflow.com/questions/24876936/… Commented Feb 27, 2015 at 19:41
  • @alex da franca did you solve your problem? I am having the same issue and I can't find a solution Commented May 25, 2015 at 14:45
  • The problem went away after a few more settings tweaks (or as it an Xcode update... ;-) I am not using RESTKit anymore, as I was looking for a "swiftier" solution. Nonetheless I use embedded Frameworks, which depend on PODs and got it to work, but it's difficult to say now what change exactly lead to success. Commented May 26, 2015 at 10:05
  • Here's how I set it up: "Project settings": Add the Cocoa Pod Build configuration file to all targets, which depend on any cocoa pod. ("Project settings" -> "Configurations") Commented May 26, 2015 at 10:14
  • "Target settings":I have the PODs and my own embedded frameworks in "Embed binaries" in the "General Tab" of the "Target settings" and in the "Build Phases" -> "Embed Frameworks" again, the PODs and my own embedded frameworks. In "Build Phases" -> "Target dependencies" only me embedded frameworks appear. Commented May 26, 2015 at 10:14

1 Answer 1

-1

You should be able to make your won private Pod. You just need to make a podspec for it. Here is an example of one.

Pod::Spec.new do |s|
  s.name         = "Commons"
  s.version      = "1.0.0"
  s.summary      = "Common code for my iOS projects."
  s.license      = {:type => 'Commercial', :text => "Copyright (c) Dan Leonard(Or Your Name?). All rights reserved." }
  s.source       = { :git => "https://github.com/PATHTOPOD", :tag =>
  s.version.to_s }
  s.homepage     = "https://github.com/PATHTOPOD"
  s.requires_arc = true

  s.ios.deployment_target = '9.0'

  s.subspec 'Core' do |ss|
    ss.source_files = '*.swift'
  end

  s.subspec 'Menu' do |ss|
    ss.source_files = 'Menu/*.swift'
    ss.resources = ['Menu/*.storyboard', 'Menu/*.xcassets']
    ss.dependency 'Alamofire'
  end
end

Then Inside your project you just have to do pod init open your podfile that was just created and add this

source 'https://github.com/CocoaPods/Specs.git'
xcodeproj 'YOURPROJECT.xcodeproj'
platform :ios, '9.0'
use_frameworks!

pod 'Commons', git: 'https://github.com/PATHTOPODPROJECT'
#pod 'Commons', :path => '/Users/YourUser/Path/To/Project/commons'

pod 'KeychainSwift'
pod 'SQLite.swift', git: 'https://github.com/stephencelis/SQLite.swift.git'

Now in this example Podfile Commons is stated twice the second is commented out. If you uncomment it and comment out the first then do pod install in your projects folder from the terminal. This will make a DevelopmentPod which is a pod that is local. This way you can make changes to the pod locally within Xcode. No switching and pod installing every time you make a change.

You will import the pod just like any other by putting

import Commons not #import <Commons/Commons.h> That is how you do it in Objective C not Swift

Once you have a working version commit it to git hub and point your project to the the github version.

Hope this helps.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, but the problem wasn't really to create an own POD, which a bit later worked and I suppose it was a version-of-cocoapods-issue, back then (a year ago). Please read the comments to the above question, that the initial problem, which was NOT creating an own pod, but rather having PODs depending on each other, has been solved by an update to cocoa pods.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.