I'm writing an app in Swift, using XCode 6 Beta-6. I'm using Cocoapods and I'm creating some unit tests.
The issue is this one: apparently is not possible to have a project that contains:
1) Project written in Swift
2) Some pods installed using cocoapods
3) A Objective-C bridge header file that imports some pods
4) Unit tests
This sounds weird, but follow my steps: after running pod install
, create the Objective-C bridge header and import one pod: everything works.
Now write some tests: in order to test your own classes, you have to import the module called "as your project" (or better, "as the main target"): in my "MyAwesomeApp" project I have to write import MyAwesomeApp
in my tests files.
Unfortunately, at this step XCode won't compile:
in my import MyAwesomeApp
line with the error "Failed to import bridging header '/path/to/MyAwesomeApp/MyAwesomeApp/MyAwesomeApp-Bridging-Header.h";
and the error "xxx.h file not found" appears in the Bridging-Header file, excluding the possibility to import a pod.
Also, if I don't import the pods in the Obj-c bridge file, the project will compile fine.
It looks that there is a conflict importing both the Objective-C Bridge Header (with Objective-C files taken from a different sub-project in the workspace) and the "main module" used for testing.
Do you know if there is a solution? What am I missing? Thanks
NOTE: As a workaround, I could import the pods in the Objective-C Bridge Header, and, instead of include the main module in my tests, add all the classes that I want to test in my "test" target. This will work, but it's not the most clean solution (I think)
CocoaPods is a tool that makes managing your project much simpler. It can save you a lot of effort and time when dealing with dependencies in your project as it makes adding, removing and updating libraries that much easier. For more on using and troubleshooting CocoaPods, check out the CocoaPods guides.
If you take a look at your main target Build Settings, you will see that there are a bunch of directories listed for the "Header Search Paths" settings.
You either need to copy those values under the test target, or you can try and modify your Podfile to include both your main and test targets and re-run install
:
platform :ios, '7.0'
link_with 'mainapp', 'mainappTests'
...
Also take care of any other header paths that could be needed and are not related to CocoaPods.
And don't forget that your classes shall have public methods wherever you want to unit-test them.
Hope this helps.
Maybe you have configured the "Objective-C Bridging Header" setting at Project level, so the "Test" target inherits that value and maybe this "Test" target is not linked with Cocoapods.
Use link_with
as @sergio suggests or set the "Pods*.debug/release" configuration for the "Test" target at "Project->Info->Configuration".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With