Cocoapods Requirement Installation and Usage with Swift
Posted By : Pawanpreet Singh | 31-Mar-2016
Requirement and Why to use it:
While developing projects we need third Party libraries, whenever we have to add new library we copy its code to our Project, while upgrading our Project to meet latest xCode requirements sometimes we need latest version of those libararies which we have added to our projects and in one project we might be using several third party libraries which we have to update, to manage all thsese headaches developers use dependency managers like CocoaPods.
Life without dependency manager:
1) Upgrading a library to a latest version can be difficult, especially if various libraries must be updated together because one can depend on another.
2) Including a library in your project makes it tempting to make local changes to the code, making it harder to update to a newer version later.
3) Determining the current version if the librabry used in your project can be a tough job especially if you are now tracking your changes.
4) Finding new libraries can be difficult without a central location to see all the available libraries.
Installation:
Open Terminal and enter the following command:
sudo gem install cocoapods
Enter your password when requested. You must use sudo to install CocoaPods, but you won’t need to use sudo after it’s installed.
Lastly, enter this command in Terminal to complete the setup:
pod setup --verbose
This process will likely take a few minutes as it clones the CocoaPods Master Specs repository into ~/.cocoapods/ on your computer.
The verbose option logs progress as the process runs, allowing you to watch the process instead of seeing a seemingly “frozen” screen.
Usage:
You first need to close Xcode.
Open Terminal and navigate to the directory that contains your IceCreamShop project by using the cd command:
cd ~/Path/To/Folder/Containing/Project
Next, enter this command:
pod init
This creates a Podfile for your project.
Type this command to open the Podfile using Xcode for editing:
open -a Xcode Podfile
The default Podfile looks like this:
# Uncomment this line to define a global platform for your project
# platform :ios, ‘8.0’
target ‘Project’ do
end
target ‘ProjectTests' do
end
Replace the two commented lines with the following:
platform :ios, "8.0"
use_frameworks!
This tells CocoaPods that your project is targeting iOS 8.0 and will be using frameworks instead of static libraries.
Now add dependency using CocoaPods. Save and Close the Podfile
You now need to tell CocoaPods to install the dependencies for your project. Enter the following command in Terminal:
pod install
This is all you need to do!
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Pawanpreet Singh
Pawanpreet is an seasoned Project Manager with a wealth of knowledge in software development, specializing in frontend and mobile applications. He possesses a strong command of project management tools, including Jira, Trello, and others. With a proven track record, he has successfully overseen the delivery of multiple software development projects, managing budgets and large teams. Notable projects he has contributed to include TimeForge, Yogyata, Kairos, Veto, Inspirien App, and more. Pawanpreet excels in developing and maintaining project plans, schedules, and budgets, ensuring timely delivery while staying within allocated resources. He collaborates closely with clients to define project scope and requirements, establish timelines and milestones, and effectively manage expectations. Regular project status meetings are conducted by him, providing clients and stakeholders with consistent updates on project progress, risks, and issues. Additionally, he coaches and mentors project leads, offering guidance on project management best practices and supporting their professional development.