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:
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:
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:
You'll notice some warnings regarding
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