Tuesday, September 15, 2015

iOS - CocoaPod


CocoaPod
This is a short tutorial about how to use CocoaPod.
CocoaPod is a dependency manager, you can compare it with Gradle for Android projects (or Maven). CocoaPod makes it easy for you to manage libraries in your Xcode projects, because CocoaPod has a database servers with a lot of popular libraries. An advantage is you don’t have to clone a library from github and than include it to your project. This is all automated for you, but before it does all the work for you, you have to to configure a file to make it work for you.

First you need to install CocoaPod on your Mac, I provide you with the following link on how to do that:

To manage your project with CocoaPod, you have to create a Podfile, you can do this by issuing the following command in your project directory:
# pod init

This will create a ‘Podfile’ which will be used by CocoaPod to read what dependencies to manage.
If you want to use FMDB library, this is a wrapper library for managing SQLite db, you add the following line between “target ‘projectname’ do” and “end”:
pod ‘FMDB'

Save file and close your editor, than execute the following command:
# pod install

You’ll see the following output of the command:
Analyzing dependencies
Downloading dependencies
Installing FMDB (2.5)
Generating Pods project
Integrating client project

After that you have to do one more thing! Close your project in Xcode and open the project with the file name projectname.xcworkspace and NOT projectname.xcodeproj anymore.

Well that’s about it. This is the basic to quickly get you started. For more fancy stuff, Google is your friend. 

No comments:

Post a Comment

NSNotification example