If you’re a beginner, you probably have wondered how to set up Cocoapods in your iOS project. Cocoapods is a dependency manager for Swift & Objective-C, and has over 24,000 libraries to spice up your application. It’s incredibly helpful to integrate code that has already been written to maximize your time working.
How to install a Cocoapod in your project
- After creating your Xcode project, open a new Terminal window
- Go into the directory your project is in (example:
YourName/Projects/MyApp/
). You may have to use multiplecd
(change directory) commands to get into it through Terminal - When you’re in the directory, type touch Podfile which will create your podfile
- Type open Podfile to open it – it should open in a text editor
- You will have a blank document. To add your Cocoapods, write the following code and replace the highlighted text:
target 'MyApp' do
pod 'AFNetworking', '~> 3.0'
pod 'FBSDKCoreKit', '~> 4.9'
end
- Save the document, go back to Terminal and type
pod install
. Your dependencies should have installed if there were no errors (read the log to be sure) - Instead of opening the
.xcodeproj,
open the.xcworkspace
file instead – keep on using the.xcworkspace
file moving forward
Read more:
Using CocoaPods: https://guides.cocoapods.org/using/using-cocoapods.html