How do I use Cocoapods in iOS Swift?

Article by: Manish Methani

Last Updated: September 24, 2021 at 2:04pm IST
2 min 45 sec read

CocoaPods is used for installing or updating third-party SDKs while working with XCode. Suppose you want to integrate Google Sign-in in your app, then you have to install google SDK. CocoaPods provides an easy way to install the third party SDK like Google Sign-In SDK. Similarly, you can install any third party library with the help of CocoaPods.

How to install CocoaPods?

You can install CocoaPods tool on OSX by running the following command in terminal

sudo gem install cocoapods

How to use Cocoapods to install any third party SDK in iOS App?

In this example, we will add Google SDK in iOS app,

1) Create an Xcode project, and Click Save. We saved the project on Desktop.

2) Create a file named Podfile in your project. This file includes all the dependencies which you want to install.

(File > New > File > Scroll Down to Others Category > Empty > Next > Save As > Podfile > Create)

 

3) Now open Podfile and add your dependencies.

platform :ios, '9.0'

target 'CodzifyProject' do
use_frameworks!

pod 'GoogleSignIn'

end

CodzifyProject is the name of my project. You must replace it it with yours. pod 'GoogleSignIn' is the Google Sign-in SDk which I took as an example to install.

4) Save the file.

5) Open a terminal and cd to the directory containing the Podfile. In my case, project is saved on Desktop.

cd Desktop
cd CodzifyProject
// Here 
CodzifyProject is the name of my sample app.

Now CodzifyProject is the directory which contains Podfile. You can check using ls command.

ls

6) Run pod install command to install the dependencies.

7) Close Xcode. Close terminal. Now you can see .workspace file of your project along with .xproject file on Desktop where your application is created. In our case, its CodzifyProject.workspace. Open it and from now onwards you can use this .workspace file when you start working on it.

In this way you can install any third party SDK using CocoaPods. Just integrate the name of dependency in Podfile and perform the given steps. You can use this link for more information on Google Developers page .

Simplified Coding for Beginners.








Download the Codzify
Mobile App


Mobile App Development, Web App Development, Programming Languages, Latest Tech News & lot more.

Codzify Mobile App

A self-paced learning Courses Created by an Engineer
For Engineers.

Premium

The Complete Angular Course

Instructor: Manish Methani

Explore Curriculum
Free

C Programming for Absolute Beginners

Instructor: Manish Methani

Start Watching
Premium

Flutter Mobile App Development Course

Instructor: Manish Methani

Explore Curriculum
Free

Learn HTML, CSS & Bootstrap

Instructor: Manish Methani

Start Watching

Test your skills with these expert-led curated
Mock Tests.

C Programming Test

Test your C Programming skills with this comprehensive mock test on C Programming.

Take Test

Flutter Test

Solve most asked Interview Questions on Flutter and Test your foundational skills in flutter.

Take Test

GATE(CSE) Operating Systems

Solve most asked GATE Questions in Operating Systems and test your Gate Score.

Take Test

HTML,CSS Test

This is a mock test designed to help you assess your knowledge and skills in HTML and CSS.

Take Test

(GATE CSE) Data Structures & Algorithms Test

Solve most asked GATE Questions in Data Structures and Algorithms and test your Gate Score.

Take Test
include_once 'codzify-footer.php'; ?>