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

你离开我真会死。 提交于 2019-12-21 05:36:37

问题


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.


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/44301971/how-to-integrate-both-objective-c-and-swift-pods-in-same-project-in-ios-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!