我可以在创建Cocoa Touch Framework时使用CocoaPod吗? [英] Can I use CocoaPods when creating a Cocoa Touch Framework?

查看:140
本文介绍了我可以在创建Cocoa Touch Framework时使用CocoaPod吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个新的Cocoa Touch Framework(MyFramework.framework),它将依赖于Alamofire。这个框架将用Swift编写。作为测试,我开始了一个新的Cocoa Touch Framework项目:

I'm creating a new Cocoa Touch Framework (MyFramework.framework), which will have a dependency on Alamofire. This framework will be written in Swift. As a test I started a new Cocoa Touch Framework project:

File > New > Project > Framework & Library > Cocoa Touch Framework

然后,在我执行的终端中:

Then, in the terminal I performed:

pod init

。在新创建的Podfile中,我添加了以下内容:

under this projects directory. In the newly created Podfile I added the following:

source 'https://github.com/CocoaPods/Specs.git'
# Uncomment this line to define a global platform for your project
platform :ios, '8.0'
# Uncomment this line if you're using Swift
use_frameworks!

pod 'Alamofire', '~> 3.0'

再次,在我执行的终端中:

Once again, in the Terminal I performed:

pod install

并开始编码。

在单视图项目中使用MyFramework.framework产品之前,一切似乎都很好。当我尝试运行该项目时,我遇到以下问题:

Everything seemed well and good till I used the MyFramework.framework Product in a Single View Project. When I attempt to run the project I get the following issue:

dyld: Library not loaded: @rpath/Alamofire.framework/Alamofire
Referenced from: /Users/me/Library/Developer/CoreSimulator/Devices/87DA70B6-49BF-441E-BD81-F4A80B0792CF/data/Containers/Bundle/Application/2E414EA8-7E54-4D71-9295-566D4FAAADE2/test.app/Frameworks/MyFramework.framework/MyFramework
Reason: image not found

我以为Cocoa Touch Framework项目本质上是动态的,因此将包括所有依赖项。

I thought that Cocoa Touch Framework projects were inherently Dynamic, and therefore would include all dependencies.

谁能告诉我为什么会这样,以及我如何解决这个问题?
这是CocoaPods的问题还是我错过了什么?

Can anyone tell me why this is happening and how I may be able to fix it? Is this an issue with CocoaPods or am I missing something?

我是Stack Overflow的菜鸟所以如果您需要更多信息,请告诉我我。

I'm a noob to Stack Overflow so please let me know if you need more information from me.

谢谢!

推荐答案

不幸的是CocoaPods不支持使用Cocoa Touch Framework目标。我在GitHub上挖掘了他们的问题时发现了一些参考文献:

Unfortunately CocoaPods doesn't support use with Cocoa Touch Framework target. I found a few references to this while digging through their issues on GitHub:


我们不支持将Pod集成到框架目标中。 。

- 2015年11月4日 neonichu


... in为了正常工作,CP需要对Xcode项目中的依赖项进行递归分析,并以某种方式确保您永远不会在另一个上下文中使用构建产品。

- neonichu 于2015年7月7日

...in order for this to "just work", CP would need to do a recursive analysis of dependencies in your Xcode project and also somehow ensure that you would never use the build product in another context.
-neonichu on Jul 7, 2015



到目前为止,我找到了两种方法来处理这个问题:


So far I've found two ways to deal with the issue:

正确的方法是为您的框架创建一个新的pod规范,并通过CocoaPods将其引入您的主项目。这解决了CococaPods对依赖图的所有问题,也是CocoaPods开发人员推荐的解决方案。

The right way is to create a new pod spec for your framework and bring it in to your main project via CocoaPods. This resolves all of the problems CococaPods has with the dependency graph and is the recommended solution from the CocoaPods developers.

简单方法包括主项目中框架中的pod。这似乎有效,但坦率地说,我不知道为什么。这是我测试项目中的Podfile:

The easy way is to include the pods from your framework in your main project. This seems to work, but frankly I don't know why. This is the Podfile from my test project:

platform :ios, '9.0'
use_frameworks!

def myfirstframework_pods
    pod 'Alamofire', '~> 3.0'
end

target 'MyApp' do
    pod 'SwiftKeychainWrapper', '~>1.0'
    myfirstframework_pods
end

target 'MyFirstFramework' do
    myfirstframework_pods
end

这篇关于我可以在创建Cocoa Touch Framework时使用CocoaPod吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆