Learn how to install and use the CocoaPods Dependency Manager in iOS development to easily add and maintain libraries. This tutorial also covers how to navigate and use Terminal, install packages, and work with Firebase through CocoaPods.
Key Insights
- The tutorial explains 'dependencies', which are libraries of code that another library requires to run, using the example of importing MapKit to a Jive Factory app.
- CocoaPods is a utility that simplifies the process of adding and maintaining libraries and their dependencies in development projects.
- The tutorial provides detailed steps for installing CocoaPods using Terminal, an application in the Utilities folder.
- Once CocoaPods is installed, the tutorial illustrates how to install dependencies in a new project, Pod Factory, using CocoaPods.
- The tutorial provides a step-by-step guide on how to create a Podfile, specify a path in Terminal, and install Firebase as a dependency using CocoaPods.
- After successfully installing Firebase with CocoaPods, the tutorial suggests following the same steps used in the Jive Factory project to build a functioning Firebase app.
Master the essentials of iOS development with this tutorial, covering topics like Cocoapods Dependency Manager and installing packages, while providing a hands-on exercise in managing project dependencies.
This exercise is excerpted from Noble Desktop’s past app development training materials and is compatible with iOS updates through 2021. To learn current skills in web development, check out our coding bootcamps in NYC and live online.
Topics covered in this iOS Development tutorial:
Installing Cocoapods Dependency Manager, Installing Packages using Cocoapods
Exercise Overview
Dependencies are libraries of code that another library needs in order to run. Remember back to an earlier exercise when we imported MapKit to our Jive Factory app? That was a dependency that we added to the project.
We will use a utility called CocoaPods, which allows developers to easily add libraries and dependencies to projects. It is commonly the case that you may want to use one library, but because it is dependent on other libraries, you’ll need to add (and maintain) them as well in order for the one library to work. CocoaPods helps simplify things for developers who want to install a library by maintaining any additional dependencies.
Installing CocoaPods
- Go into your Applications > Utilities folder and launch Terminal.
-
In Terminal, install CocoaPods by typing:
sudo gem install cocoapods
- Hit Return.
- Next to Password: type in your computer’s password (the password won’t show in Terminal but don’t worry, it’s there).
- Hit Return.
Once Cocoapods is ready to go, we can begin installing dependencies! Create a new project called Pod Factory. We installed Firebase using the Swift Package Manager in our Jive Factory app, we are going to use Cocoapods in this bonus exercise instead.
- Click on the Pod Factory project name (not the folder) at the top of the Project navigator to open the Project Settings Editor.
- Go to File > New > File (Cmd–N).
- In the Filter text box search for Empty, scroll down to the Other section and double–click on Empty.
- Next to Save As, type: Podfile
- You should be in the Pod Factory folder, so click Create.
- In the Project navigator, make sure Podfile is selected.
-
It is currently blank. Type:
target "Pod Factory" do pod 'Firebase/Database' end
NOTE: Each pod consists of a library and its dependencies.
Close and save the Xcode project.
-
Now we need to navigate to our Podfile in the Terminal. Open Terminal (Applications > Utilities > Terminal) if it isn’t already open, then type cd followed by a single space.
NOTE: cd stands for change directory.
- There is an easy way of specifying a path in Terminal. Open a Finder window and navigate to: Desktop > Class Files > Pod Factory
- Drag the Pod Factory folder and drop it onto the Terminal window.
- Return to Terminal. You should see the path has automatically been entered.
- Hit Return. Now we are inside the Pod Factory folder.
-
Type the following:
pod install
-
Hit Return and wait for installation to complete. It could take several moments.
NOTE: If you encounter errors completing the pod installation, you may need to update to new pods. In your Terminal, type pod update and hit Return. Once this completes, you will need to type pod install and hit Return again.
Feel free to read more about the Firebase setup by going to firebase.google.com/docs/ios/setup.
Once Terminal is done installing the pod, go back to Xcode and make sure the Pod Factory project is not open.
In a Finder window, navigate into: Desktop > Class Files > Pod Factory
-
Notice a new file called Pod Factory.xcworkspace has been created. Open it.
NOTE: You should now work from this file instead of the Pod Factory.xcodeproj file.
In the Project navigator, notice there are two targets: Pod Factory and Pods
You have successfully installed Firebase with Cocoapods! You can now follow the same Jive Factory project steps to build a working Firebase app with Cocoapods as the dependency manager.