旧图书馆,新的CocoaPods [英] Old libraries, new CocoaPods

查看:81
本文介绍了旧图书馆,新的CocoaPods的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为 CocoaPods 0.36 对任何人都有用,他们现在正在使用Swift和Frameworks支持我今天有一个问题困扰着我......

Because CocoaPods 0.36 are availbable to anyone and they are now coming with Swift and Frameworks support I have one question that is bothering me today...

我在项目目录中创建 Podfile ,填写:

I create Podfile in my project directory, fill it with:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'

pod 'AFNetworking'
pod 'SwiftyJSON'

并像往常一样运行 pod install 你知道这个故事。但是,当我打开我的 .xcworkspace 并转到任何ViewController和导入SwiftyJSON 它只是有效,但当我尝试做与AFNetworking相同的事情我得到没有这样的模块'AFNetworking'。当然,我可以创建一个 Bridging-Header 并使用Objective-C方式导入它,但当我读到这个博文我可以看到:

And run pod install as usual... You know this story. But when I open my .xcworkspace and go to any ViewController and import SwiftyJSON it just works but when I try to do the same thing with AFNetworking I get No such module 'AFNetworking'. Of course, I can create a Bridging-Header and import it with the Objective-C way but when I read this blog post I can see:


使用这个swift中的subspec,没有生成的伞头,你
需要创建一个桥接头并使用像 #import
< AFNetworking / AFNetworking + UIKit.h 。使用生成的伞
标头,如果您的Podfile中包含subpec
,则只需要导入AFNetworking

如果我错了,请纠正我,但我想如果我们使用CocoaPods添加库,则不再需要手动Bridging-Header,对吧?那么,为什么这不起作用?

Correct me if I'm wrong but I suppose that manual Bridging-Header is no longer needed if we add libraries with CocoaPods, right? So, why this isn't working?

推荐答案

正如我想的那样......我在OP中提供的这个例子是不正确的。 ..好吧,基本上它是正确的,因为它的工作方式应该如此。让我向您展示一个反例。

As I thought... This example which I provided in OP is incorrect... Well, basically it's correct because it's working like it should. Let me show you a counter example.

我有一个Swift项目,但我只想使用Objective-C pods(AFNetworking,SSPullToRefresh等)。现在我们遇到了一些麻烦,因为当您在 Podfile 中提供这些Objective-C pod时,它们将作为静态库添加到Pods目标中。您现在可能已经将CocoaPods切换为框架(如果您想了解其中的差异,请阅读 this 问题)。返回主题...此冲突引用有两种可能的解决方案:

I have a Swift project but I want to use only Objective-C pods (AFNetworking, SSPullToRefresh etc.). Now we have some troubles because when you provide those Objective-C pods in Podfile they'll be added to Pods target as a static libraries. You probably now that CocoaPods are now switching to Frameworks (If you want to know the difference please read this question). Back to topic... There are two possible solutions to this conflict sitation:


  1. 您手动创建 YourProject-Bridging -Header.h #import 这些库......这是在Swift集成之前使用的旧方法。

  2. 您在 Podfile 中包含了这个神奇的 use_frameworks!方法调用。通过这样做,你强制CocoaPods创建框架而不是静态库。

  1. You manually create YourProject-Bridging-Header.h and #import those libraries... This is the old way used even before Swift integration.
  2. You include this magic use_frameworks! method call inside your Podfile. By doing this you force CocoaPods to create frameworks instead of static libraries.

现在,让我解释为什么你更喜欢第二种解决方案......正如OP所述,CocoaPods现在自动创建伞头了解他们)。这是您跳过手动创建桥接标题的便捷方式。

Now, let me explain why you'd prefer the second solution... As OP states, CocoaPods now automatically create Umbrella Headers (learn about them). It's the convenient way for you to skip manual creation of bridging header.

我找到了解决方案这里所以如果没有这篇文章,我可能仍会在努力解决这个问题。为作者干杯!

I've found a solution here so without this post I would probably still be struggling with this problem. Cheers to the author!

这篇关于旧图书馆,新的CocoaPods的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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