Anilkumar iOS Developer
Anilkumar iOS Developer

Reputation: 3745

How to integrate both Objective-C and Swift pods in same project in iOS app

I am doing Objective-C in iOS app. But the problem is I want to add few Objective-C apis into that I added successfully earlier with cocoa pods, But, now I want to add Swift Api through cocoa pods, but the problem getting while installing is following.

[!] 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 Pods being used are: apis

But I can't add this manually due to its large api and it contains sub folders.

But, if I remove "#" key from use_frameworks!, its getting installed, but, the old Objective-C apis getting file not found in my project. Even I have very basic knowledge at installing frameworks/apis through cocoa pods.

Can any one suggest me how to over come this.

Upvotes: 3

Views: 1709

Answers (3)

Giang
Giang

Reputation: 3635

Podfile file:

 platform :ios, '10.0'
    use_frameworks!

    def pods
        pod 'Alamofire', '= 4.4'
        pod 'SwiftyJSON' '= 3.1.4'
        pod 'MBProgressHUD'
    end

    target 'YourProject' do
        pods
    end

YourProject-Bridging-Header.h

#import <MBProgressHUD/MBProgressHUD.h>

Build Settings enter image description here

Upvotes: 0

Bilal
Bilal

Reputation: 19156

use_frameworks! will work with Objective-C pod only if they are dynamic frameworks not static libraries. Most of the popular third party libraries are using dynamic frameworks like AFNetworking, GoogleMaps etc.

Make sure all your Objective-C pods are dynamic frameworks. If you are not sure just create a sample project with cocoapods and use use_frameworks!. Try adding one by one, all the pods and find out which one is the culprit.

Upvotes: 1

TawaNicolas
TawaNicolas

Reputation: 646

I had that problem once, what I did was use use_frameworks! like you mentioned, and then I changed how the Objective-C imports are written.

The command use_frameworks! turns each pod into a Framework, so in your projects the .h and .m files are no longer visible to the import like they would usually.

As a result, instead of using for example #import <AFNetworking/AFNetworking.h>, you do @import AFNetworking;

From my own experience, and maybe it was just a special case for my project. But turning everything into frameworks slowed down the compile time on Xcode and it made my App Package bigger for some reason.

Upvotes: 0

Related Questions