[英]How to integrate both Objective-C and Swift pods in same project in iOS app
I am doing Objective-C in iOS app. 我在iOS应用程序中做Objective-C。 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. 但问题是我想添加几个Objective-C apis到我之前成功添加的可可豆荚,但是,现在我想通过可可豆荚添加Swift Api,但是安装时遇到的问题如下。
[!] Pods written in Swift can only be integrated as frameworks; [!]用Swift编写的Pod只能作为框架集成; add use_frameworks!
添加use_frameworks!
to your Podfile or target to opt into using it. 您的Podfile或目标选择使用它。 The Swift Pods being used are: apis 正在使用的Swift Pod是:apis
But I can't add this manually due to its large api and it contains sub folders. 但我不能手动添加它,因为它的大api和它包含子文件夹。
But, if I remove "#" key from use_frameworks!, its getting installed, but, the old Objective-C apis getting file not found in my project. 但是,如果我从use_frameworks中删除“#”键,它就会被安装,但是,在我的项目中找不到旧的Objective-C apis获取文件。 Even I have very basic knowledge at installing frameworks/apis through cocoa pods. 即使我对通过可可豆荚安装框架/ apis有非常基本的了解。
Can any one suggest me how to over come this. 任何人都可以建议我如何过来这个。
use_frameworks!
will work with Objective-C
pod only if they are dynamic frameworks not static libraries. 只有当它们是动态框架而不是静态库时才会使用Objective-C
pod。 Most of the popular third party libraries are using dynamic frameworks like AFNetworking
, GoogleMaps
etc. 大多数流行的第三方库都使用动态框架,如AFNetworking
, GoogleMaps
等。
Make sure all your Objective-C
pods are dynamic frameworks. 确保所有Objective-C
pod都是动态框架。 If you are not sure just create a sample project with cocoapods
and use use_frameworks!
如果您不确定只是使用cocoapods
创建示例项目并使用use_frameworks!
. 。 Try adding one by one, all the pods and find out which one is the culprit. 尝试逐个添加所有pod并找出哪一个是罪魁祸首。
I had that problem once, what I did was use use_frameworks!
我曾经遇到过这个问题,我做的是使用use_frameworks!
like you mentioned, and then I changed how the Objective-C imports
are written. 就像你提到的那样,然后我改变了Objective-C imports
的编写方式。
The command use_frameworks!
命令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. 原来每荚成框架,所以在项目h和.m文件不再可见的import
像他们通常会。
As a result, instead of using for example #import <AFNetworking/AFNetworking.h>
, you do @import AFNetworking;
因此,不要使用例如#import <AFNetworking/AFNetworking.h>
,而是使用@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. 但是将所有内容都转换为框架会减慢Xcode的编译时间,并且由于某种原因它使我的应用程序包更大。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.