简体   繁体   English

在cocoapods项目中处理外部的非cocoapods框架

[英]Handle external not-cocoapods-framework in a cocoapods project

I fell in love with Cocoapods and I want to migrate all my projects with it. 我爱上了Cocoapods,我想用它迁移所有项目。 Before doing it, I've a few questions on how to handle external not-cocoapods frameworks in my projects. 在开始之前,我对如何在项目中处理外部的非cocoapods框架有一些疑问。

1) Let's say that I'm using Cocoapods and I've included only AFNetworking framework. 1)假设我使用的是Cocoapods,并且仅包含AFNetworking框架。 At some point, I need to use some CoreGraphic animation and I need to use QuartzCore : AFNetworking is not using this framework, so QuartzCore is not included in my Pods project. 在某些时候,我需要使用一些CoreGraphic动画,并且需要使用QuartzCore :AFNetworking没有使用此框架,因此QuartzCore不包含在我的Pods项目中。 What's the best way to handle this situation? 处理这种情况的最佳方法是什么?

Is better to think "I put all the frameworks in my Pods project, so in my "app project" I've only the code necessary to my app"? 最好考虑一下“我将所有框架都放在了Pods项目中,所以在我的“应用程序项目”中,我只有应用程序所需的代码”? And if yes, how? 如果是的话,怎么办? Adding in my Pods.xconfig this code 在我的Pods.xconfig添加此代码

OTHER_LDFLAGS = -ObjC ... -framework QuartzCore OTHER_LDFLAGS = -ObjC ...-框架QuartzCore

? Or there are other (better) ways? 还是还有其他(更好)的方法?

Or is better to think "this is not a Pod, so I add the framework on my "app project" as I've always done before"? 还是最好考虑一下“这不是Pod,所以我像以前一样将框架添加到我的“应用程序项目”中”?

2) I've a library (saved in my HD) that is not on the main repository of Cocoapods and there is no Podspec file: what's the best way to include it on my project? 2)我有一个库(保存在我的HD中),不在Cocoapods的主存储库上,也没有Podspec文件:将其包括在我的项目中的最佳方法是什么?

  • I create a podspec for that library and I link it using :local attribute on my Podfile 我为该库创建一个podspec,并在Podfile上使用:local属性将其链接

  • I add that library in my "app project" as I've always done 我一如既往地将库添加到“应用程序项目”中

Of course every way works fine, so I'm not asking "How to add an external framework", I'm asking what's the best way to do it :) 当然,每种方法都可以正常工作,所以我不是在问“如何添加外部框架”,而是在问什么是最好的方法:)

Framework 骨架

CocoaPods tries, to the possible extent, to separate its files from your work. CocoaPods尽可能尝试将其文件与您的工作分开。 This is also needed because CocoaPods needs to control some files. 这也是必需的,因为CocoaPods需要控制某些文件。 For example the Pods.xcconfig is assumed to be under CocoaPods control and it is recreated during each installation. 例如,假定Pods.xcconfig在CocoaPods控制之下,并且在每次安装过程中都会重新创建它。 In other words any change that you make to it is lost. 换句话说,您对其所做的任何更改都将丢失。

So if you need a framework you should add it to your app project. 因此,如果您需要框架,则应将其添加到您的应用程序项目中。 In principle you should do it even if the framework is included by some Pods because they might be updated removing the dependency and your project would break. 原则上,即使某些Pod包含了框架,您也应该这样做,因为可能会对其进行更新以删除依赖关系,并且您的项目可能会中断。

Custom library 定制图书馆

Both alternatives work, if you plan to reuse the library creating the podspec might come handy in future. 这两种选择的工作,如果你打算重用库创建podspec可能在将来来得心应手。 You could also create a custom repo (see the wiki) so you don't need to use the :local option. 您也可以创建自定义存储库(请参阅Wiki),因此无需使用:local选项。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM