Xcode can't see objects added via Cocoapods

12,709

Solution 1

Once you use use_frameworks! in your Podfile, Objective-C Pods like SSKeychain also get build as frameworks.

The actual problem is that only module imports work in the bridging header when using frameworks. Also, you might want to get rid of the bridging header entirely, as it is unnecessary when using frameworks, they can be imported directly in Swift.

Solution 2

To clarify what you should do to make it work:

  1. Be sure to have use_frameworks! in your Podfile
  2. It doesn't matter if you have a Bridging header or not. Leave it untouched
  3. In your SWIFT file just use import Podname

That's it, you're good to go. Of course it may happen that you need to clean your project or maybe delete the derived data folder. Build and you can use it.

Solution 3

If you're not using any swift pods,

Try removing the use_frameworks! on your Podfile.

Run pod install on terminal.

Clean & Build !

I spent almost half an hour fixing it, I tried adding those paths on Search Paths or re-adding the bridging-header but the error was the same.

Therefore, in my case, bridging header file was not the problem, its on the Podfile .

I hope it helps!

Share:
12,709
Johnathon Sullinger
Author by

Johnathon Sullinger

Johnathon works full-time as an Enterprise Infrastructure Sr. Manager, responsible for 3 physical data centers and an enterprise presence on public cloud platforms. He manages the teams responsible for the server and network infrastructure along with the application development and support teams and teams adopting new cloud technologies. His current mission is migrating data centers to the public cloud and fostering a culture of DevOps within his organization. In his spare time he works on open source projects he has hosted on GitHub. Has builds software applications that target both Microsoft's .NET Core and NodeJS. You can follow him on Twitter

Updated on June 07, 2022

Comments

  • Johnathon Sullinger
    Johnathon Sullinger about 2 years

    I have a podfile defined with the following pods.

    platform :ios, '8.0'
    use_frameworks!
    
    target 'LifeStream' do
    pod 'SSKeychain'
    pod 'LiveSDK'
    pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'swift-2.0'
    end
    

    I installed the pods and opened up my workspace. I have found that any usage of Alamofire works fine, due to the Swift 2 version of it importing the project as a framework.

    When I try to use SSKeychain classes however, I receive a

    Use of unresolved identifier 'SSKeychain`

    Same applies with any class I try to use in the LiveSDK.

    I have a bridge header in my projects root directory, and the project is configured to use it.

    #ifndef Header_h
    #define Header_h
    
    #import "SSKeychain/SSKeychain.h"
    #import "LiveSDK/LiveConnectClient.h"
    
    #endif /* Header_h */
    

    if I change the #import from

    #import "SSKeychain/SSKeychain.h"
    

    to

    #import "SSKeychain.h"
    

    Xcode fails to compile because it can't find the file. So I assume that the bridge header is working, as the way my bridge header is built now does not generate any compiler errors caused by not finding the headers.

    Bridge Header

    Objective-c Bridging header

    Framework Search Paths

    I have also added my project root directory to the framework search path.

    Framework search paths

    Linked Frameworks

    Lastly I have linked all of the frameworks to the project as well.

    Linked frameworks

    Am I missing something with my setup? I have not been able to get Cocoapods to work on my project for nearly a week now. I even created a brand new project thinking that mine was just messed up; which didn't change a thing. I don't know what to do from here in order to resolve this.

    Edit

    After doing some additional research, I found a blog post showing that you have to include your Pods directory in the User Header Search

    User Header Search

    A commenter also mentioned that if you are using the newer Cocoapods Frameworks support for Swift, then it will need to include the Frameworks/** search path. I've included both Pods/** and Frameworks/** but still have the same issue.

    After some further reading, it's beginning to sound like this is a limitation of Cocoapods. From what I understand, you can't use libraries and frameworks together at the same time in a project.

  • Johnathon Sullinger
    Johnathon Sullinger almost 9 years
    I'm not sure how to go about doing that sorry. I've removed the bridging header, and the reference to it in my build settings. Swift still can't find the LiveSDK or SSKeychain framework. When I use import SSKeychain, i'm given a No such model 'SSKeychain' compiler error.
  • Johnathon Sullinger
    Johnathon Sullinger almost 9 years
    This ended up fixing my issue. When I was getting these errors, I had went and removed use_frameworks! from my podfile to see about just reverting to static instead of dynamic. Once I put that back in, removed the bridge and added the import in my class, everything came together perfectly. Thanks for the help.
  • Alexei S.
    Alexei S. almost 9 years
    I'd be very thankful if one of you could demonstrate the solution with a bit more clarity... I don't know whether I can get rid of my bridging header entirely because I integrate some libraries like parse.com written in objective-C as well.
  • nickdnk
    nickdnk over 8 years
    I am struggling with this. I can add @import SSKeyChain, build, archive, run and everthing, but I still have a red line under the import statement saying "Module SSKeyChain not found" ? How is this possible when it works?