Reputation: 103
I am using cocoa pod version 1.1.1, swift 3.0.1 and Xcode 8.1. I have an app, which used cocoa pod like this (Podfile)
# 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
And I have some objective-C file also, that's why I used Bridging-Header.h file.
//
// 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"
When I run the TestApp, it's run perfectly. But I run the unit test cases, I got an error on TestAppTests -> Swift compiler error -> Failed to import bridging header "TestApp-Bridging-Header.h" on #import "GoogleAnalytics/GAI.h" not found.
I fix this issue, using this technique on 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
I just want to know below mention points, when I migrate the code to Swift 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?
Please explain the reasons.
Upvotes: 4
Views: 1257
Reputation: 441
Adding the specific framework to the test target works for me. In my case when running unit testing one of the frameworks didn't found by the linker.
After editing my Podfile as follow I were able to run my tests:
target 'MyTarget' do
pod 'somePod'
pod 'somePod2'
target 'MyTargetTests' do
inherit! :search_paths
pod 'somePod2'
end
end
Upvotes: 1
Reputation: 13514
As the unit test cases contains different target you must install cocoapods to that target. So what you did about is correct.
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. Is it require to install every pods in different targets? or we have any alternate solution.
Yes you need to install pods on all different targets.
2. What is the best technique to handle this kind of problems?
This is one of the way most people doing.
But for more complex things if you would like to do then take this Reference.
Upvotes: 1