CocoaPods: an effective solution for installing the same pod in multiple targets, cocoapodspod
One of the exciting features of Xcode7 is the ability to perform native UI testing (thanks to Apple), so when I develop a new Xcode 7/Swift 2 project, I put the focus on this. In the unit test process, Quick and Nimble are really comfortable to use, so I also want to use these class libraries in the UI test.
Using CocoaPods to install Quick and Nimble is simple, but the problem is that you just want to install Quick and Nimble to the test target.
A bad habit but effective solution
The initial method is to place Quick and Nimble in the two targets of Podfile respectively:
# Podfileplatform :ios, '9.0'use_frameworks!# My other podstarget 'MyTests' do pod 'Quick', '0.5.0' pod 'Nimble', '2.0.0-rc.1'endtarget 'MyUITests' do pod 'Quick', '0.5.0' pod 'Nimble', '2.0.0-rc.1'end
I don't like Quick and Nimble. I will repeat them twice here. Every time I update the version, I have to modify it in two places.
Incorrect Solution
Later, I Googled and found that I needed to use link_with. I think all the databases below link_with will be applied to the target I specified:
# Podfileplatform :ios, '9.0'use_frameworks!# My other podslink_with 'MyTests', 'MyUITests'pod 'Quick', '0.5.0'pod 'Nimble', '2.0.0-rc.1'
As a result, I fully understand link_with and how it works. In addition to test targets, Quick and Nimble are also installed in the main target of my app.
Elegant solution
Solution:
# Podfileplatform :ios, '9.0'use_frameworks!# My other podsdef testing_pods pod 'Quick', '0.5.0' pod 'Nimble', '2.0.0-rc.1'endtarget 'MyTests' do testing_podsendtarget 'MyUITests' do testing_podsend
I forgot that Podfile is actually a ruby file! Thanks @ NeoNacho for saving me one day!