Cocoapods Swift does not work with use_frameworks! Fix

I have a mixed Objective-C/Swift project and activated use_frameworks! in my podfile because I wanted to use a Swift-based pod. In order to enable the usage of the Objective-C-based pods in your Swift code, I thought it would be necessary to stick to the common approach of including the pods’ header files into a bridging header file and configure the project in Xcode accordingly. Like so.

But, as it turns out, you do not have to do this if add use_frameworks! is active in your podfile. All you need to do is import the according pod framework directly in your Swift code. For instance, when using AFNetworking add an
import AFNetworking
to the top of your Swift file. That is all.

Posted in Cocoa, iOs, Swift Tagged with: cocoa pods, import, podfile, problem, swift
  • Jergo_Mayor

    Im trying to use GoogleidentityToolkit library to handle login an things. As you did, I activated use_frameworks! on my pod file, but the module GITkit cant be found. I’m trying to figure out whats going. As far as I know if you use “use_frameworks” you don’t need to create any bridging header file, since cocoapods compiles down the library into a single module, so later you can imported as usual on your*.swift files.

  • yes, as to the usage of an Objective-C-based pod in a Swift project, that sounds correct. i simply include the pod as usual in the podfile and then run pod install. afterwards, i can use an ‘import podname’ in my Swift file and this works out.

    however, there might be issues with your build configuration. after you run pod install, are there some warnings written in the command line?