2016-11-11 85 views
4

我使用的是可可豆荚版本1.1.1,swift 3.0.1和Xcode 8.1。我有一个应用程序,它使用可可豆荚像这样(Podfile)cocoa pod:Swift编译器错误“无法导入桥接头”原因?

# Uncomment this line to define a global platform for your project 
# platform :ios, '6.0' 
platform :ios, '8.0' 
use_frameworks! 

target 'TestApp' do 
    pod 'GoogleAnalytics', '~> 3.14.0' 
end 

target 'TestAppTests' do 
    pod 'Quick' 
    pod 'Nimble' 
end 

而且我有一些客观-C文件还,这就是为什么我用桥接-Header.h文件。

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

#import <CommonCrypto/CommonCrypto.h> 

#import <GoogleAnalytics/GAI.h> 
#import <GoogleAnalytics/GAIFields.h> 
#import <GoogleAnalytics/GAIDictionaryBuilder.h> 
#import <GoogleAnalytics/GAILogger.h> 

#import <CoreBluetooth/CoreBluetooth.h> 

#import "AModel+Level.h" 
#import "AModel+AutoStatus.h" 
#import "AModel+Settings.h" 
#import "APacketData+Decoders.h" 
#import "Reachability.h" 

当我运行TestApp时,它完美运行。但是我运行单元测试用例,在TestAppTests上出现错误 - > Swift编译器错误 - >无法在#import“GoogleAnalytics/GAI.h”中导入桥接头“TestApp-Bridging-Header.h”未找到。

我解决这个问题,使用上podfile这种技术:

platform :ios, '8.0' 
use_frameworks! 

target 'TestApp' do 
    pod 'GoogleAnalytics', '~> 3.14.0' 
end 

target 'TestAppTests' do 
    pod 'GoogleAnalytics', '~> 3.14.0' 
    pod 'Quick' 
    pod 'Nimble' 
end 

我只是想知道下面提点,当我的代码迁移到斯威夫特3.0.1:

1. Is it require to install every pods in different targets? or we have any alternate solution. 
2. What is the best technique to handle this kind of problems? 

请解释原因。

回答

1

由于单元测试用例包含不同的目标,您必须将cocoapods安装到该目标。所以你所做的是正确的。

platform :ios, '8.0' 
use_frameworks! 

target 'TestApp' do 
    pod 'GoogleAnalytics', '~> 3.14.0' 
end 

target 'TestAppTests' do 
    pod 'GoogleAnalytics', '~> 3.14.0' 
    pod 'Quick' 
    pod 'Nimble' 
end 

1.是否需要将每个吊舱安装在不同的目标中?或者我们有其他解决方案。

是的,你需要在所有不同的目标上安装豆荚。

2.处理这类问题的最佳方法是什么?

这是大多数人在做的一种方式。

但是,对于更复杂的事情,如果你想要做,然后采取这种Reference

+0

为什么我把同样的吊舱在两个目标,此前它的正常工作。 –

+0

我想你可以将目标从Xcode添加到如果你不想使用pod添加。 –

0

将特定框架添加到测试目标适用于我。 在我的情况下,运行单元测试其中一个框架没有被链接器找到。

编辑我Podfile如下之后,我能够运行我的测试:

target 'MyTarget' do 

    pod 'somePod' 
    pod 'somePod2' 

    target 'MyTargetTests' do 
     inherit! :search_paths 

     pod 'somePod2' 
    end 
end 
+0

也许你可以考虑提供更多的细节 – Panther

+0

你是对的,编辑,谢谢。 – EdiZ