简体   繁体   English

如何在iOS应用程序中将Objective-C和Swift pod集成到同一项目中

[英]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. 大多数流行的第三方库都使用动态框架,如AFNetworkingGoogleMaps等。

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的编译时间,并且由于某种原因它使我的应用程序包更大。

Podfile file: Podfile文件:

 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 YourProject桥接,Header.h

#import <MBProgressHUD/MBProgressHUD.h>

Build Settings 构建设置 在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在同一项目中同时使用Realm Swift和Realm Objective-C - Use both Realm Swift and Realm Objective-C in same project 同时具有Objective-c和Swift的iOS应用-优点和缺点 - iOS app that has both Objective-c and Swift - pros & cons 将Swift Project集成到Objective-C应用程序中 - Integrate Swift Project in An Objective-C application 如何为Objective-C和Swift创建通用iOS库? - How to make an universal iOS library for both Objective-C and Swift? 将 iOS 框架(Swift/Objective-C)导入到 Android 应用程序项目中? - Import an iOS framework (Swift/Objective-C) into an Android app project? 如何删除use_frameworks! 并继续在 Objective-C 项目中使用 swift pods? - How to remove use_frameworks! AND keep using swift pods on an objective-c project? 如何手动将Swift静态库集成到Objective-C或Swift项目中而不将其添加为子项目 - How to manually integrate a Swift static lib into an Objective-C or Swift project without adding it as a subproject 在iOS上集成Amazon Payments(Swift或Objective-C) - Integrate Amazon Payments on iOS (Swift or Objective-C) 如何在Xcode项目中集成和使用Font Awesome与Objective-C或Swift? - How to integrate and use Font Awesome with Objective-C or Swift in an Xcode project? 项目中带有Objective-C和Swift的类前缀 - Class prefixes in project with both objective-c and swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM