lunes, 23 de noviembre de 2015

iOS: CocoaPods

CocoaPods is an open source dependency manager for Swift and Objective-C Cocoa projects.

1) Get CocoaPods

     $ sudo gem install cocoapods

2) If you have a project with no podfile

2.1) Open the terminal and navigate to your projects location
2.2) Execute "pod init"*
2.3) Open your podfile in Xcode or use "open -a Xcode Podfile"
2.4) Remove the comment tag 


     # Uncomment this line to define a global platform for your project
     # platform :ios, "6.0"

Use the proper platform number

Your Podfile should look like the following by now:

xcodeproj ‘MyProject.xcodeproj'

     # Uncomment this line to define a global platform for your project
     # platform :ios, '8.0'
     # Uncomment this line if you're using Swift
     # use_frameworks!

     platform :ios, '8.0'

     target 'MyProject' do

     end

     target 'MyProjectTest’ do

     end

3) Then you can add any cocoa pod, for instance AFNetworking by adding the following between platform and target:

     source 'https://github.com/CocoaPods/Specs.git'
     pod 'GoogleMaps'

and execute

     $ cd <path-to-project>

     $ pod install

4) From now on you should always open your project via .xcworkspace rather than from the .xcodeproj

NOTES:

*In Swift you need to use "use_frameworks!" inside the target. Sometimes the podfile es empty it need to have a target, such as:

target '<proyect_name>' do
use_frameworks!
#pod "AFNetworking"

end