Mobile Development: Cocoapods
In this post you will find how to setup Cocoapods into your Objective-C application project.
Cocoapods
Cocoapods is an open-source dependency manager for Objective-C applications. By using Cocoapods you can find and use many usefull libraries that will help you in making a great apps.
Installation
Cocoapods is written in Ruby. To install Cocoapods, you can simply run:
sudo gem install cocoapodsSetup project
After creating your Objective-C project, in your project directory you can run:
pod initThat command will create file named Podfile. You can specify your dependencies in that file. Then run this command to setup your project and install the dependencies.
pod installNow you should open <your-project-name>.xworkspace to open your project.
Search dependencies
To search a dependency you can go to Cocoapods, or run:
pod search <keywords>Add dependencies
You should add your dependency into Podfile.
platform :ios, '7.1'
pod 'AFNetworking', '2.0'
pod 'Facebook-iOS-SDK', '~> 3.10.0'
pod 'your-dependency'After that run:
pod updateBy running that command cocoapods will install:
AFNetworkingwith version2.0Facebook-iOS-SDKwith version3.10.0or version up to3.11not3.11or higheryour-dependencywith lastest version
Notice that in Podfile you can specify the version of a dependency you use.
The other ways to specify dependency version:
'~> 2.0'means version2.0and version up to3.0not including3.0or higher'> 2.0'means any version higher than2.0'>= 2.0'means any version higher than2.0including2.0'< 2.0'means any version lower than2.0'<= 2.0'means any version lower than2.0including2.0'2.0'means version2.0- leave blank means latest version
Conclusion
- Install Cocoapods
- Find libraries/dependencies that suit your needs
- Tell Cocoapods to install your dependencies
- Have fun