xcode 结合 Cocoapods 和 Carthage

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29234348/
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-15 06:51:44  来源:igfitidea点击:

Combine Cocoapods and Carthage

iosxcodeswiftcocoapodscarthage

提问by Rengers

I'm creating a Swift framework that is dependent on several other third party frameworks. Both these other frameworks support Carthage and Cocoapods.

我正在创建一个依赖于其他几个第三方框架的 Swift 框架。这两个其他框架都支持 Carthage 和 Cocoapods。

Is there any way I can make my own framework support installing using both Carhage and Cocoapods? Or is just not achievable and should I just pick one?

有什么方法可以让我自己的框架支持使用 Carhage 和 Cocoapods 进行安装?或者只是无法实现,我应该选择一个吗?

采纳答案by Keith Smiley

You can definitely make your framework available with both CocoaPods and Carthage. This is the path that I would recommend to allow your users to use whatever solution they prefer. Also note that setting a framework up to work with Carthage also makes it much easier for users who want to use your library without either of these solutions.

你绝对可以让你的框架同时适用于 CocoaPods 和 Carthage。这是我建议的路径,允许您的用户使用他们喜欢的任何解决方案。另请注意,将框架设置为与 Carthage 一起使用也使想要在没有这些解决方案的情况下使用您的库的用户更容易。

On a high level, for CocoaPods you'll want to create a podspec that lists your dependencies there. This way CocoaPods will manage downloading and configuring them along with resolving them against other user dependencies. See more here.

在高层次上,对于 CocoaPods,您需要创建一个 podspec,在那里列出您的依赖项。这样 CocoaPods 将管理下载和配置它们,并根据其他用户依赖项解析它们。在此处查看更多信息

For Carthage you'll want to configure your project with framework targets for the platforms you support and add your dependencies in your Cartfile. More on that here

对于 Carthage,您需要使用您支持的平台的框架目标配置您的项目,并在您的 Cartfile 中添加您的依赖项。更多关于这里

回答by zvonicek

Combining both is actually not difficult. With my framework I have started with CocoaPods template containing Exampleand Poddirectories. In the example project I created a new Cocoa Touch Frameworktarget, made sure this target is Shared (in Product - Schemes - Managed Schemes) and dragged content of my Pod/Classesdirectory to the project (with unchecked Copy items if neededand added Target Membershiponly to this newly created framework).

两者结合其实并不难。在我的框架中,我从包含ExamplePod目录的CocoaPods 模板开始。在示例项目中,我创建了一个新Cocoa Touch Framework目标,确保该目标是共享的(在产品 - 方案 - 托管方案中)并将我的Pod/Classes目录的内容拖到项目中(未选中Copy items if neededTarget Membership仅添加到这个新创建的框架中)。

This should be enough, Carthage should find this shared scheme and use it. Just keep in mind you have to commit changes and create a new git tag before using your framework from Carthage.

这应该就够了,迦太基应该找到这个共享方案并使用它。请记住,在使用来自 Carthage 的框架之前,您必须提交更改并创建新的 git 标签。