Xcode 看不到通过 Cocoapods 添加的对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31103831/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode can't see objects added via Cocoapods
提问by Johnathon Sullinger
I have a podfile
defined with the following pods.
我podfile
定义了以下豆荚。
platform :ios, '8.0'
use_frameworks!
target 'LifeStream' do
pod 'SSKeychain'
pod 'LiveSDK'
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'swift-2.0'
end
I installed the pods and opened up my workspace. I have found that any usage of Alamofire works fine, due to the Swift 2 version of it importing the project as a framework.
我安装了 pods 并打开了我的工作区。我发现 Alamofire 的任何用法都可以正常工作,因为它的 Swift 2 版本将项目作为框架导入。
When I try to use SSKeychain classes however, I receive a
然而,当我尝试使用 SSKeychain 类时,我收到一个
Use of unresolved identifier 'SSKeychain`
使用未解析的标识符“SSKeychain”
Same applies with any class I try to use in the LiveSDK.
这同样适用于我尝试在 LiveSDK 中使用的任何类。
I have a bridge header in my projects root directory, and the project is configured to use it.
我的项目根目录中有一个桥头文件,项目配置为使用它。
#ifndef Header_h
#define Header_h
#import "SSKeychain/SSKeychain.h"
#import "LiveSDK/LiveConnectClient.h"
#endif /* Header_h */
if I change the #import
from
如果我改变#import
从
#import "SSKeychain/SSKeychain.h"
to
到
#import "SSKeychain.h"
Xcode fails to compile because it can't find the file. So I assume that the bridge header is working, as the way my bridge header is built now does not generate any compiler errors caused by not finding the headers.
Xcode 无法编译,因为它找不到文件。所以我假设桥头正在工作,因为我的桥头现在构建的方式不会因找不到头而产生任何编译器错误。
Bridge Header
桥头
Framework Search Paths
框架搜索路径
I have also added my project root directory to the framework search path.
我还将我的项目根目录添加到框架搜索路径中。
Linked Frameworks
链接框架
Lastly I have linked all of the frameworks to the project as well.
最后,我还将所有框架都链接到了该项目。
Am I missing something with my setup? I have not been able to get Cocoapods to work on my project for nearly a week now. I even created a brand new project thinking that mine was just messed up; which didn't change a thing. I don't know what to do from here in order to resolve this.
我的设置是否遗漏了什么?近一个星期以来,我一直无法让 Cocoapods 为我的项目工作。我什至创建了一个全新的项目,认为我的项目搞砸了;这没有改变任何事情。我不知道该怎么做才能解决这个问题。
Edit
编辑
After doing some additional research, I found a blog postshowing that you have to include your Pods directory in the User Header Search
在做了一些额外的研究之后,我发现了一篇博客文章,表明你必须在用户标题搜索中包含你的 Pods 目录
A commenter also mentioned that if you are using the newer Cocoapods Frameworks support for Swift, then it will need to include the Frameworks/** search path. I've included both Pods/** and Frameworks/** but still have the same issue.
一位评论者还提到,如果您使用的是对 Swift 的更新 Cocoapods Frameworks 支持,那么它需要包含 Frameworks/** 搜索路径。我已经包含了 Pods/** 和 Frameworks/** 但仍然有同样的问题。
After some further reading, it's beginning to sound like this is a limitation of Cocoapods. From what I understand, you can't use libraries and frameworks together at the same time in a project.
一些经过进一步的阅读,它开始听起来像这样的的CocoaPods的限制。据我了解,您不能在一个项目中同时使用库和框架。
采纳答案by NeoNacho
Once you use use_frameworks!
in your Podfile, Objective-C Pods like SSKeychain also get build as frameworks.
一旦use_frameworks!
在 Podfile 中使用,像 SSKeychain 这样的 Objective-C Pod 也可以构建为框架。
The actual problem is that only module imports work in the bridging header when using frameworks. Also, you might want to get rid of the bridging header entirely, as it is unnecessary when using frameworks, they can be imported directly in Swift.
实际问题是在使用框架时,只有模块导入在桥接头中起作用。此外,您可能希望完全摆脱桥接头,因为在使用框架时没有必要,它们可以直接在 Swift 中导入。
回答by Simon C.
To clarify what you should do to make it work:
澄清你应该做什么才能使它工作:
- Be sureto have
use_frameworks!
in your Podfile - It doesn't matter if you have a Bridging headeror not. Leave it untouched
- In your SWIFT file just use
import Podname
- 一定有
use_frameworks!
你的Podfile - 您是否有桥接头并不重要。保持原样
- 在您的SWIFT 文件中,只需使用
import Podname
That's it, you're good to go. Of course it may happen that you need to clean your project or maybe delete the derived data folder. Build and you can use it.
就是这样,你可以走了。当然,您可能需要清理项目或删除派生数据文件夹。构建并且您可以使用它。
回答by Azel
If you're not using any swift pods,
如果您没有使用任何 swift pods,
Try removing the use_frameworks!
on your Podfile.
尝试删除use_frameworks!
Podfile 上的 。
Run pod install on terminal.
在终端上运行 pod install。
Clean & Build !
清洁与建造!
I spent almost half an hour fixing it, I tried adding those paths on Search Paths or re-adding the bridging-header but the error was the same.
我花了将近半个小时来修复它,我尝试在搜索路径上添加这些路径或重新添加桥接头,但错误是一样的。
Therefore, in my case, bridging header file was not the problem, its on the Podfile.
因此,就我而言,桥接头文件不是问题,它在Podfile 上。
I hope it helps!
我希望它有帮助!