Xcode Swift Pod安装-找不到导入文件 [英] Xcode Swift pods installation - import file not found

查看:479
本文介绍了Xcode Swift Pod安装-找不到导入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Swift编写的Xcode项目。我正在使用两个Pod, AFNetworking BDBOAuth1Manager 。它们都是Obj-C库,因此导入它们的简单桥接文件就可以处理一切。

I'm working on a project in Xcode written in Swift. I'm using two pods, AFNetworking and BDBOAuth1Manager. They're both Obj-C libraries, so a simple bridging file to import them takes care of everything.

现在,当我尝试添加第三个Pod时,问题就来了, SwiftyJSON ,是用Swift编写的。 Podfile如下所示:

Now, the problem arrises when I try to include a third pod, SwiftyJSON, that's written in Swift. Here's what the Podfile looks like:

platform :ios, "8.0"
use_frameworks!

pod "AFNetworking"
pod "BDBOAuth1Manager"
pod "SwiftyJSON"

link_with 'TwitterSearch', 'TwitterSearch Tests'

安装上面的Podfile之后,桥接头文件停止工作,因为它现在找不到我正在尝试的文件

After installing the above Podfile, the bridging header stops working, because it now it can't find the files I'm trying to import.

为清楚起见,这是桥接头文件:

To clarifty, this is the bridging header file:

//
//  Use this file to import your target's public headers that you would like to expose to Swift.
//

#import "BDBOAuth1RequestOperationManager.h"

当Pod只是用Obj-C编写的 AFNetworking BDBOAuth1Manager 时,它可以工作。当包含第三个以Swift编写的Pod SwiftyJSON 时,此功能不起作用。

It works when the Pods are just AFNetworking and BDBOAuth1Manager, which are written in Obj-C. It doesn't work when a third pod, SwiftyJSON, written in Swift, is included.

确切的错误消息为:


  • 快速编译器错误:找不到
    文件 BDBOAuth1RequestOperationManager.h

  • Swift编译器错误:无法导入桥接头文件

    到桥接头文件的路径

任何想法

更新:我已经弄清楚了为什么它不起作用。当我手动添加SwiftyJSON时,一切正常。整个问题都归结于这一行: use_frameworks!
我对框架一点都不熟悉,但是实际上您必须执行以下操作:

UPDATE: I've figured out why it wasn't working. When I manually added in SwiftyJSON, everything worked fine. The entire problem roots back to this line: use_frameworks! I'm not at all familiar with frameworks, but practically speaking you'd have to do the following:

#import "path/BDBOAuth1RequestOperationManager.h"

instead of

#import "BDBOAuth1RequestOperationManager.h"


推荐答案

解决方法


Podfile

platform :ios, "8.0"
use_frameworks!

target 'SwiftAndObjCPods' do
pod "SwiftyJSON"
end

target 'SwiftAndObjCPodsTests' do
pod "SwiftyJSON"
end

项目:

拖曳将 AFNetworking BDBOAuth1Manager 的当前版本直接放入项目中。您可以通过将其定位在 Pods 组>中进行操作。豆荚在Finder中显示,然后将其移动到方便的临时位置。

Drag & drop the current versions of AFNetworking and BDBOAuth1Manager directly into your project. You can do so by locating these in the Pods group > Pods > Show in Finder, and simply move these to a convenient tmporary location.

Bridging-Header.h

#import "AFNetworking.h"
#import "BDBOAuth1RequestOperationManager.h"

快速使用

// No import
let a = BDBOAuth1RequestOperationManager(baseURL: baseURL, consumerKey: "consumer", consumerSecret: "secret")

经过测试:链接,构建,运行。

这篇关于Xcode Swift Pod安装-找不到导入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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