How to use CocoaPods with SpriteBuilder
SpriteBuilder is a great tool for building games on iOS, and CocoaPods is a great tool for managing dependencies in your Xcode projects. With a little extra work, you can use both together.
First, create a SpriteBuilder project, and make sure you have CocoaPods installed.
Then, create a Podfile inside your SpriteBuilder project's package:
cd /path/to/MyProject.spritebuilder
vi Podfile
In this example, we'll add networking support to our SpriteBuilder project with the popular AFNetworking library. Edit the contents of your Podfile to the following:
source 'https://github.com/CocoaPods/Specs.git'
pod 'AFNetworking'
The first line tells CocoaPods where to look for pods. The second line declares 'AFNetworking' as a dependency in our project. Save your Podfile, then run:
pod install
You'll notice some warnings regarding HEADER_SEARCH_PATHS
and OTHER_LDFLAGS
, and if you try to use AFNetworking at this point, you'll receive compiler and linker errors. In fact, these warnings tell us exactly how to fix our problem, so let's do that.
CocoaPods creates an Xcode workspace (MyProject.xcworkspace) alongside your Xcode project (MyProject.xcodeproj) to configure your Pods, so open up the newly created workspace.
Then, in Xcode, click the Project Navigator tab and navigate to Targets > MyProject iOS > Build Settings. From there:
- Find the "Header Search Paths" setting.
- Click the value, then "+" to add
$(inherited)
to the top of the list. - Repeat for the "Other Linker Flags" setting.
Viola! Now you can include <AFNetworking/AFNetworking.h>
and use the library in your project. To use other Pods, search the Pods repository at cocoapods.org, then simply add it to your Podfile and pod install
.