6
votes

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.

1
@alex da franca did you solve your problem? I am having the same issue and I can't find a solution - Raphael Royer-Rivard
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. - alex da franca
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") - alex da franca
"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. - alex da franca

1 Answers

-1
votes

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.