avatarEniela P. Vela

Summary

This web content provides a concise guide on how to install and use CocoaPods, a dependency manager for Swift and Objective-C Cocoa projects, akin to npm for NodeJs or React.

Abstract

The article titled "Get Started with CocoaPods" serves as a brief tutorial for integrating CocoaPods into a Swift programming project. It explains that CocoaPods is a dependency manager that simplifies the process of including third-party libraries in Xcode projects. The guide outlines two main steps: installing CocoaPods on your computer using the Ruby gem package manager, and then integrating specific pods (libraries) into your project. The process involves creating a Podfile, which is a text file that lists the dependencies required for the project. The article illustrates this with an example using the Alamofire library, demonstrating how to initialize the Podfile, add the desired pod, install it, and finally, open the generated Xcode workspace to start using the library within the project.

Opinions

  • CocoaPods is likened to npm, implying it is an essential tool for Cocoa developers, similar to how npm is essential for NodeJs or React developers.
  • The guide emphasizes the importance of CocoaPods in managing library dependencies efficiently, suggesting it enhances the engagement with and discoverability of open-source libraries.
  • By specifying the version of Alamofire ('~> 5.2'), the article conveys the opinion that developers should control the versions of their dependencies to ensure compatibility and stability in their projects.
  • The congratulatory remarks after each major step suggest that the process of integrating CocoaPods is straightforward and a cause for accomplishment for developers who are new to the tool.

Get Started with Cococapods

A short guide on how to get started with CocoaPods.

If you are new in Swift programming look at cocoapods as the npm in NodeJs or React. Just like npm, Cocoapods is a dependency manager for Cocoas projects.

CocoaPods manages library dependencies for your Xcode projects.

The dependencies for your projects are specified in a single text file called a Podfile. CocoaPods will resolve dependencies between libraries, fetch the resulting source code, then link it together in an Xcode workspace to build your project.

Ultimately the goal is to improve discoverability of, and engagement in, third party open-source libraries by creating a more centralised ecosystem.

source from https://guides.cocoapods.org/using/getting-started.html

1. Install CocoaPods in your PC

Please keep in mind that cocoapods is built with Ruby so it will require a sudo default command. Open your terminal and press:

$ sudo gem install cocoapods

Congratulation! You just installed cocoapods in your pc but that doesn’t mean you will get that automatically in your project.

2. Install Pods in your Project

For the purpose of this mini tutorial we are going to create a new empty project and we are going to save it in Desktop. Please remember where you save the project because it will be useful in the next step.

Figure 1. Create a new swift project

If we go to our project folder, it should look like the Figure 2. Our project is saved on .xcodeproj extention.

Figure 2. New project folder saved on Desktop

Now, we are going to our terminal and accessing our project folder from there.

Figure 3. Terminal view

Press:

$ pod init
Figure 4. Terminal pressed pod init

We are going to see that after pod init command, it is created a new Podfile.

Go ahead and open that file either through terminal or through folder finder. The file inside will look more or less like figure 5. Lets just add a new pod in the file. For this example we are going to use Alamofire. Press inside the Podofile and save the file.

 pod Alamofire
Figure 5. Podfile view. Adding Alamofire POD

You can also use:

pod 'Alamofire', '~> 5.2'

This way you specify what version of Alamofire you would like to install.

Back to the Terminal and Press:

pod install

Be patient until the pod is installed. Once it does install successfully, make sure to close the project in Xcode and open the .xcworkspace (Figure 6)

Figure 6. Creating of xcworkspace file.

Congratulation! YOU MADE IT!

Thank you for your attention!

iOS
Swift
Swift Programming
Xcode
Cocoapods
Recommended from ReadMedium