Cocoapods Dependency Manager

Free iOS Development Tutorial

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

  1. Go into your Applications > Utilities folder and launch Terminal.
  2. In Terminal, install CocoaPods by typing:

    sudo gem install cocoapods
    
  3. Hit Return.
  4. Next to Password: type in your computer’s password (the password won’t show in Terminal but don’t worry, it’s there).
  5. Hit Return.
Full-Stack Web Development Certificate: Live & Hands-on, In NYC or Online, 0% Financing, 1-on-1 Mentoring, Free Retake, Job Prep. Named a Top Bootcamp by Forbes, Fortune, & Time Out. Noble Desktop. Learn More.

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.

  1. Click on the Pod Factory project name (not the folder) at the top of the Project navigator to open the Project Settings Editor.
  2. Go to File > New > File (Cmd–N).
  3. In the Filter text box search for Empty, scroll down to the Other section and double–click on Empty.
  4. Next to Save As, type: Podfile
  5. You should be in the Pod Factory folder, so click Create.
  6. In the Project navigator, make sure Podfile is selected.
  7. It is currently blank. Type:

    target "Pod Factory" do
    pod 'Firebase/Database'
    end
    

NOTE: Each pod consists of a library and its dependencies.

  1. Close and save the Xcode project.

  2. 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.

  3. There is an easy way of specifying a path in Terminal. Open a Finder window and navigate to: Desktop > Class Files > Pod Factory
  4. Drag the Pod Factory folder and drop it onto the Terminal window.
  5. Return to Terminal. You should see the path has automatically been entered.
  6. Hit Return. Now we are inside the Pod Factory folder.
  7. Type the following:

    pod install
    
  8. 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.

  9. Once Terminal is done installing the pod, go back to Xcode and make sure the Pod Factory project is not open.

  10. In a Finder window, navigate into: Desktop > Class Files > Pod Factory

  11. 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.

  12. 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.

Noble Desktop Publishing Team

The Noble Desktop Publishing Team includes writers, editors, instructors, and industry experts who collaborate to publish up-to-date content on today's top skills and software. From career guides to software tutorials to introductory video courses, Noble aims to produce relevant learning resources for people interested in coding, design, data, marketing, and other in-demand professions.

More articles by Noble Desktop Publishing Team

How to Learn iOS & Web Development

Master iOS development, web development, coding, and more with hands-on training. iOS development involves designing apps for Apple mobile devices with tools like Xcode and SwiftUI.

Yelp Facebook LinkedIn YouTube Twitter Instagram