xcode 如何在嵌入式框架中使用 Cocoapods?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24175697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:07:16  来源:igfitidea点击:

How do I use Cocoapods in an embedded framework?

xcodecocoa-touchcocoapodsxcode6

提问by richrad

I'm using an embedded framework for my custom views in a new project to take advantage of the new @IBDesignable stuff in Xcode 6 and I'd like to animate said views with Facebook's Pop. I've added Pop to the project using Cocoapods but the embedded framework doesn't have access to those files ('POP/pop.h' file not found).

我正在一个新项目中为我的自定义视图使用嵌入式框架,以利用 Xcode 6 中新的 @IBDesignable 东西,我想用 Facebook 的 Pop 为所述视图设置动画。我已使用 Cocoapods 将 Pop 添加到项目中,但嵌入式框架无权访问这些文件 ( 'POP/pop.h' file not found)。

I tried copying the Cocoapods-related build phases from the app target to the custom framework target but they don't work as-is. What doeswork is copying the Pop folder into the embedded framework directly, but then Xcode tells me that I've gotta change all of the angle brackets <POP/pop.h>to quotes "POP/pop.h". I'm assuming there's a better way and I'm blanking on it.

我尝试将与 Cocoapods 相关的构建阶段从应用程序目标复制到自定义框架目标,但它们无法按原样工作。什么的工作是直接复制文件夹流行到嵌入式框架,但随后的Xcode告诉我,我的宝贝,所有的尖括号的改变<POP/pop.h>来报价"POP/pop.h"。我假设有更好的方法,但我对此感到茫然。

回答by Anthony Persaud

Assuming in your Podfile you are using the link_with 'MyCustomFramework', where 'MyCustomFramework' is your embedded framework name, and have run pod install. Select your Project file (Blue on the top right) and go into "Build Settings". Then, find 'Allow non-modular includes in Framework Modules' and set it to YES, for both the Project file (blue) and the Custom Framework target (ex. MyCustomFramework - orange "lunchbox case" icon).

假设您在 Podfile 中使用的是link_with 'MyCustomFramework',其中“MyCustomFramework”是您嵌入的框架名称,并且已运行pod install. 选择您的项目文件(右上角的蓝色)并进入“构建设置”。然后,对于项目文件(蓝色)和自定义框架目标(例如 MyCustomFramework - 橙色“午餐盒案例”图标),找到“允许非模块化包含在框架模块中”并将其设置为YES

Setting build settings for non-modular includes

为非模块化包含设置构建设置

Then you can include cocoa pods stuff in your main MyCustomFramework.h file. Including CocoaPods in CustomFramework

然后你可以在你的主 MyCustomFramework.h 文件中包含可可豆荚的东西。 在 CustomFramework 中包含 CocoaPods

Then just import '@import MyCustomFramework;' in your Application target, and you'll get the rest of the CocoaPods at your disposal. (Ex. showing you access to 'each' from ObjectiveSugar). Importing CustomFramework into AppDelegate

然后只需导入'@import MyCustomFramework;' 在您的应用程序目标中,您将获得其余的 CocoaPods。(例如,显示您从 ObjectiveSugar 访问“每个”)。 将 CustomFramework 导入 AppDelegate

Whether you should do this or not is a separate issue, but this allows your Custom Framework to include the CocoaPods libraries in itself, which then allows the Application target to just include your Custom Framework and gets all the CocoaPods as well.

您是否应该这样做是一个单独的问题,但这允许您的自定义框架本身包含 CocoaPods 库,然后允许应用程序目标仅包含您的自定义框架并获取所有 CocoaPods。

Sorry for the multiple images, but I like to be visual.

抱歉有多个图像,但我喜欢视觉化。

回答by Rivera

I guess you are modifying the framework to use Pop. In this case you'll also need to add the Pop headers' path to the framework Build Settings' search header paths.

我猜您正在修改框架以使用 Pop。在这种情况下,您还需要将 Pop 标头的路径添加到框架构建设置的搜索标头路径中。

But then if you're modifying the framework you could just create a podspecfor it as well and let CocoaPods handle everything (and send a pull request to the creator?).

但是如果你正在修改框架,你也可以为它创建一个podspec并让 CocoaPods 处理所有事情(并向创建者发送拉取请求?)。



As for the bounty question.

至于赏金问题。

A framework should never embed other libraries. If for instance you want to use AFNetworking in your library:

框架永远不应该嵌入其他库。例如,如果您想在库中使用 AFNetworking:

  • State that AFNetworking is required in your own framework installation instructions.
  • If you distribute binaries you just build locally against AFNetworking headers. Users will need to provide their own AFNetworking when linking their App.
  • If you distribute source code with your framework (if users have to build it themselves) then ask in your installation steps to set the AFNetworking headers path in your frameworks Build Settings Header Search Paths and preset it to common paths such as POD_ROOT, etc.
  • 在您自己的框架安装说明中声明需要 AFNetworking。
  • 如果您分发二进制文件,您只需根据 AFNetworking 标头在本地构建。用户在链接他们的应用程序时需要提供他们自己的 AFNetworking。
  • 如果您将源代码与您的框架一起分发(如果用户必须自己构建它),那么请在您的安装步骤中要求在您的框架 Build Settings Header Search Paths 中设置 AFNetworking 标头路径并将其预设为常见路径,例如POD_ROOT等。

Then it works but you have complex installation instructions, users have to manually add resources if any, it is hard to control the AFNetworking version being added by users and most will never upgrade your framework because it may break their setup. All good reasons to support CocoaPods by creating a podspec (you can keep maintaining the framework/static library project if you really want).

然后它可以工作,但是您有复杂的安装说明,用户必须手动添加资源(如果有),很难控制用户添加的 AFNetworking 版本,并且大多数人永远不会升级您的框架,因为它可能会破坏他们的设置。通过创建 podspec 来支持 CocoaPods 的所有充分理由(如果你真的想要,你可以继续维护框架/静态库项目)。