Cocoapods - include certain dependencies only for XCTest files - cocoapods

I have the following Podfile:
platform :ios, '7.0'
pod 'CocoaLumberjack'
target :MyProjectTests do
pod 'OCHamcrest'
end
I want to include CocoaLumberjack in all targets and OCHamcrest only in the test target. This seems to work great when I was using GHUnit (as I had to create a specific GHUnit test target).
However, I thought I would try XCTest to see how I like it (given that GHUnit seems to be getting a few cobwebs and has changed ownership recently).
When I check my Pods.xconfig, it shows that it is including OCHamcrest
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers" "${PODS_ROOT}/Headers/CocoaLumberjack" "${PODS_ROOT}/Headers/OCHamcrest"
So, it looks like XCTests are not a separate target.
What can I do to ensure that I'm not including testing frameworks in my release build? Is this something I have to manually manage or can Cocoapods do this for me?,

This should do the trick.
target :MyProjectTests, :exclusive => true do
pod 'OCHamcrest'
end
Source: http://guides.cocoapods.org/syntax/podfile.html#target

Related

pod in testing target return no such module error

I have the following pod file, which works fine for my normal code but as soon as I want to import a pod from the test target in one of my tests it says No such module. I have tried building for testing, building for normal, I literally tried everything that came up in my mind without luck. What am I doing wrong here?
target 'MyApp' do
use_frameworks!
pod 'RxSwift'
target 'MyAppTests' do
inherit! :search_paths
# Pods for testing
pod 'RxTest'
pod 'RxBlocking'
end
end
I use CocoaPods 1.2.1
I found this post helpful. By making sure I had the same path values and user defined variables in both targets, I was able to get passed this error.

Using Cocoapods in a Workspace with two apps

I have two apps (xcode projects) that i want to have in one workspace. Since Cocoapods usually generates the workspace, i looked to see if it was possible to do this and found some answer. The recommended Podfile would look like:
workspace 'TestWorkspace'
target 'TestApp1' do
xcodeproj 'testApp1/testApp1.xcodeproj'
workspace 'TestWorkspace'
pod 'AFNetworking'
end
workspace 'TestWorkspace'
target 'TestApp2' do
xcodeproj 'TestApp2/TestApp2.xcodeproj'
pod 'MBProgressHUD'
end
(sorry wasn't sure how to have SO format the Ruby code)
So my folder structure looks like a TestWorkspace folder, with the two App projects folders, and the Podfile. Running pod install
[!] xcodeproj was renamed to project. Please update your Podfile accordingly.
and..
[!] CocoaPods did not set the base configuration of your project because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target TestApp1 to ../Pods/Target Support Files/Pods-TestApp1/Pods-TestApp1.debug.xcconfig or include the ../Pods/Target Support Files/Pods-TestApp1/Pods-TestApp1.debug.xcconfig in your build configuration (TestApp1/Pods/Target Support Files/Pods-TestApp1/Pods-TestApp1.debug.xcconfig).
So my question is what changes must be made to wind up with my TestWorkspace workspace having three projects: TestApp1, TestApp2, and Pods?
(btw, i changed the true names of my projects/workspaces to pseudo-aliases for the purposes of posting here. Hopefully, I changed everything faithfully.)
EDIT: Ok so i fixed the first warning (just a change in podfile syntax from xcodeproj to project). However, my workspace is definitely not being configured properly. I don't even see a Pod project after pod installing.
EDIT2: OK so i fixed the second warning by setting both project configuration files (debug and release) to "none". So now I have no errors, but the Pod project is still no where to be found. (Sorry if i'm solving parts of the question but I think its better to add edits than to create a new question).
Use the targets as scopes for the xcproject/workspaces. Update the podfile to something like this:
workspace 'TestWorkspace'
target 'TestApp1' do
xcodeproj 'testApp1/testApp1.xcodeproj'
workspace 'TestWorkspace'
pod 'AFNetworking'
end
target 'TestApp2' do
xcodeproj 'TestApp2/TestApp2.xcodeproj'
workspace 'TestWorkspace'
pod 'MBProgressHUD'
end
Now run pod install --verbose

Cocoapods use_frameworks! caused strange compiler errors in the old OC codes

I added use_frameworks! in my pod file, running pod install again (without any other changes). Then I got the compiler error like 'Masonry.h' file not found with <angled> include; use "quotes" instead.
Although I believed those pod header files should be used with <...> I did change them to "...". But then I got the error like Redefinition of 'FMTokenizerCursor' (from FMDB pod)
I felt like this maybe a cocoapod bug (I am using 1.0.1) so I upgraded it to cocoapods-1.1.0.beta.2, same error. pod deintegrate & pod install made no difference.
I found these is a similar question here. But the answers there did not work for me.
I tried both Xcode 7 & 8, clean ~/Library/Developer/Xcode/DerivedData
same error too.
I met the same problem as you, I try to search for Search Paths in the Build Settings of the project, then add to the User header search paths $ (SRCROOT) and select recursive. But that does not work ... Then I put the "use_frameworks!" was removed from the podfile, recompile the project, problem solved =-=
Here's an example for a Podfile using the new format. (This example project has 2 targets), Try it.
also, make sure you don't edit this file in textEdit. (xCode is preferred)
abstract_target 'YourProject-abstract' do
use_frameworks!
pod 'Alamofire', '3.5.0'
pod 'ObjectMapper'
pod 'FBSDKLoginKit'
pod 'FBSDKCoreKit'
pod 'AlamofireImage'
target 'MyProject' do
end
target 'MyProject-staging' do
end
end

Creating a static library with Cocoapod Dependencies

I'm trying to create a static library in Xcode. My library consists of a single class. It depends on another library (RXCollections).
My tests also depend on other libraries: OCMock, and Foundry.
For my static library project, I created a podfile for my static library project as such:
platform :ios, "7.1"
pod "RXCollections", '~> 1.0'
target :LibraryTests, :exclusive => true do
pod "OCMock", '3.1.1'
pod "Foundry"
end
Everything builds successfully, but when I run my tests, I get a runtime exception when I try to use RXCollections methods: -[__NSCFSet rx_mapWithBlock:]: unrecognized selector sent to instance 0x7feaf414c410.
What's going wrong here?
UPDATE
Well, that didn't take long ;) Turns out, CocoaPods was automatically adding LibPods.a to my target's "Link Binary with Libraries" build phase, but for some reason, I had to remove that and add the LibRXCollections.a specifically. Still not sure why. Any ideas?

Kiwi and CocoaPods with a static shared library

I have a workspace with 3 projects:
MyApp
Common
Pods
Common is a common library that MyApp depends on. I'd like to setup CocoaPods and Kiwi to work correctly in this project. How do I go about this?
I found https://stackoverflow.com/a/16472563/62, but when I try to follow this approach, I get an error when building MyApp before I even try adding Kiwi:
ld: library not found for -lPods
Here's the repo on GitHub: https://github.com/lyahdav/cocoapods_kiwi_shared_library
My Podfile is:
workspace 'MyApp.xcworkspace'
platform :ios, '7.0'
target 'Common' do
xcodeproj 'Common/Common.xcodeproj'
pod 'AFNetworking'
pod 'Reachability'
target 'MyApp', :exclusive => true do
xcodeproj 'MyApp.xcodeproj'
end
end
I finally found a working solution for this. Here's the Podfile:
platform :ios, '7.0'
workspace 'MyApp.xcworkspace'
xcodeproj 'MyApp'
pod 'CupertinoYankee', '~> 1.0'
target :MyAppTests, :exclusive => true do
pod 'Kiwi/XCTest'
end
target :Common, :exclusive => true do
xcodeproj 'Common/Common'
pod 'CupertinoYankee', '~> 1.0'
end
target :CommonTests, :exclusive => true do
xcodeproj 'Common/Common'
pod 'Kiwi/XCTest'
end
This example Podfile shows both MyApp and Common configured to use Kiwi for tests and they can both use pods (CupertinoYankee in this example).
I did manually have to configure in Xcode that MyApp links with Common with these steps:
In MyApp project settings > MyApp target > Build Phases > Link
Binary With Libraries > add libCommon.a
In MyApp project settings > Build Settings > User Header Search Paths > add ${SRCROOT}/Common/Common/**
This repo has a working example: https://github.com/lyahdav/cocoapods_kiwi_shared_library
The only slightly annoying thing I didn't manage to figure out was if there's a way to not duplicate each pod that I want to use both in MyApp and Common. If anyone has a solution that does all of what my solution does and solves that, I'll gladly mark it the accepted answer.
Posted as an edit by anonymous user. Here's his answer:
I have forked the repository and made few changes for new cocoapods versions to make it still working.
platform :ios, '8.0'
workspace 'MyApp.xcworkspace'
project 'MyApp'
target :MyApp do
pod 'CupertinoYankee', '~> 1.0'
end
target :MyAppTests do
pod 'Kiwi/XCTest'
end
target :Common do
project 'Common/Common'
pod 'CupertinoYankee', '~> 1.0'
end
target :CommonTests do
project 'Common/Common'
pod 'Kiwi/XCTest'
end
https://github.com/chrishunterkiller/cocoapods_kiwi_shared_library
I'm not sure how to fix the setup you have, but if I were you I would make Common into its own Pod. Pods can be private and just stored in GitHub as a repo. Of course, you need a podspec for Common but I built a sample to test that setup for our build service and it took me less than 30 mins to get it right.
Then in your Podfile for MyApp, you do something like this:
pod 'Common', :git => 'git#github.com:lyahdav/Common.git', :commit => 'a1b2c3d'
And AFNetworking and Reachability can be referenced in the podspec of Common (assuming that's the right dependency).
This setup also allows you to include Common in whatever other apps you're building without having to embed the code. Again, making assumptions about what you're trying to achieve, so add more detail to the question if that's not right.
You could hack a solution that may get broken again, or better yet as Common is your library, start using CocoaPods for your Common library as well.
It will show up as a local "Dvelopment Pod", which means that you can directly edit the library code as well.
To begin easily just create a Common.podspec at the root folder:
$ pod lib create Common
Then just edit the minimum required parameters, such as platform, source_files, requires_arc and dependency if any.
You can take a look at how your library looks as you change it (and compare it to what you had with your manually created Common library):
$ pod lib lint --no-clean Common.podspec
Finally remove the no-longer needed Common from your workspace and add this to your Podfile:
pod 'Common', :path => '../Relative/Path/To/CommonSources/'
It will take you no more than 30 minutes and you'll learn many things in the process.
Next you could take a look at making private pod repositories.

Resources