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

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

问题描述

我正在创建一个新的 Cocoa Touch 框架 (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 集成到框架目标中...
-neonichu 2015 年 11 月 4 日

We don't really support integrating Pods into framework targets...
-neonichu on Nov 4, 2015

...为了使其正常工作",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 将其引入您的主项目.这解决了 CocoaPods 与依赖关系图的所有问题,并且是 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 框架时可以使用 CocoaPods 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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