11

am using CocoaPods 1.2 and i have a project with 2 targets, one is the main iPhone app and the other one is cocoa touch framework library.

I have no problem adding pods to my iphone target, my main problem is that i cannot add any pods to that other shared library target.

here is an example of my pod file:

platform :ios, '9.0'

target 'MyApp' do
  use_frameworks!
  pod 'EVReflection'
end

target 'MyLibrary' do
  use_frameworks!
  pod 'EVReflection'
end

adding pods to the main app MyApp works just fine but not to the other target, any ideas why this happens?

i have tried to use abstract_target but with no luck. i even tried to deintegrate and reintegrate but also not working.

the problem only happens when trying to add pods to universal framework library, adding pods to any other type of targets work just fine.

Any help would be appreciated.

3
  • Does cocoapods give you an error? Or is Xcode complaining? Commented Feb 13, 2017 at 14:36
  • No error from cocoapods or xcode, pods install successfully and xcode runs just fine, but when u try to import the pod in the library it says module not found Commented Feb 13, 2017 at 14:38
  • I'm pretty sure I've done this in the past and not had an issue, but I'll put together a little sample and see what I find. Commented Feb 14, 2017 at 4:02

2 Answers 2

13
+100

Here is my whole procedure

  1. crate a new swift app project.
  2. create a new cocoa touch framework target.
  3. in the project directory , run pod init
  4. Tyr This Podfile

    # Uncomment the next line to define a global platform for your project
    platform :ios, '9.0'
    
    target 'SOQ' do
      use_frameworks!
    end
    
    target 'SOQFW' do
      use_frameworks!
    end
    
    pod 'EVReflection'
    

after pod install, in both my two targets SOQ (swift app) and SOQFW (cocoa touch framework) can import EVReflection in *.swift and user class EVObject without a problem.

sample code is

import EVReflection

class User: EVObject {
    var id: Int = 0
    var name: String = ""
    var friends: [User]? = []
}

you can give it a try.

My development environment is os x 10.12 , xode 8.2.1 , cocoapods 1.1.1

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

2 Comments

I did create a new project and 2 targets and it did work fine, so i wondered what i was doing wrong in the other project, after investigating more, i discovered that because i selected also a 3rd target in the File inspector "Target membership" window of that "User" class in your example, i also needed to add EVReflection pod to that third target and now it works fine, thanks
It is not working if one of your framework is in Objective-C, and it says [!] Pods written in Swift can only be integrated as frameworks; add use_frameworks! to your Podfile or target to opt into using it. The Swift Pod being used is: SwiftyJSON-library
1

I created a sample project here: https://github.com/dtweston/PodFrameworkTest

My Podfile was the exact same as you posted in your question.

I was able to import and use the framework in both the main app and the framework library.

In the framework:

public class LibUser: EVObject {
    var id: Int = 0
    var name: String = ""
    var friends: [LibUser]? = []
}

In the app (you can see this also references the framework's LibUser class):

class AppUser: EVObject {
    var id: Int = 0
    var name: String = ""
    var friends: [LibUser]? = []
}

I'm also on macOS 10.12 and Xcode 8.2.1. I'm using cocoapods 1.2.0, and it also worked fine with Cocoapods 1.2.0-rc1

I wonder what's different between your setup and mine. If you look at the Info for the project that contains your App and framework, are the Cocoapods config files set up correctly?

1 Comment

Thank you, your sample works fine, i discovered that my problem has something to do with the fact that i actually had 3 targets and the second target was selecting the third target from File inspector "Target membership" window, so i didnt know that i need to add my pod to both targets even am not importing the EVReflection pod to that third target, thanks for your effort, i wish i could split the bounty between you guys but i don't think its possible, i will mark the answer above right since he did post it earlier

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.