Getting Started with private Pods – Josh Software

When working on larger projects, you should write a separate code for reuse in the library. On iOS, CocoaPods It’s a great tool for dealing with app dependencies, and it also lets you create your own library as a Cocoa Pod.
CocoaPods is a tool for adding open source code to your project. Creating a private pod helps in publishing the set of lessons or framework you have built and is available for others to use in the private organization.

The Benefits of Pods over a Static Library:

  1. It may not be easy to find a manually added dependency for another programmer. Backpacks ensure you can go through the backpack or Podfile scheme to understand what you used.
  2. Replacing lib in a new version is a pain. When you need to delete previous files manually and add new ones – too many clicks. Installing a pod will do this automatically with a single command.
  3. Light Repo: Because it is recommended that you only commit your code and leave the pod for the next one using pod install whenever a new user pulls your code. Cocoapod brightens up your code folder. If you ever need to make a change in any pod, it is always advisable to submit a PR request and update it so that other users can benefit from your amazing work.
  4. Removing the backpack is easy.

Steps for creating a private pod:

  1. Install Cocoapods on your Mac
  2. Create a repository in Git
  3. Repository of clones
  4. Create your own directory
  5. Add functionality
  6. Check the Podspec file
  7. Make changes to Git
  8. Install Pod in your project

Let’s examine these steps one by one:

Install Cocoapods on your Mac

To install Cocoapods on your Mac, open the terminal and type the command below

$ sudo gem install cocoapods

2. Create a repository in Git

First of all, you need to create the private ‘Podspec’ database. To do this, you must first create a repository on Github (or any other platform).
To do this:

  1. Go to Github
  2. Create a new repo
  3. Select the private option and name your specification database. In this case, we created a repository called “private-repo-1” on Github.)

Lay down the reservoir:

Click the green “Code” button and copy the database URL. Duplicate the repository with the above Mac URL.

4. Create your own directory

To create a private pod, run the command below in the terminal in your repository folder

$ pod lib create RandomNumberGenerator

After entering this command, a series of questions will be asked.

  • When asked which platform you want to use, answer iOS.
  • When asked what language you would like to use, answer Swift.
  • When asked if you would like to include a demo application, answer yes.
  • When asked which test frame to use, answer no
  • Do not follow instructions for viewing-based testing.

Example for reference

Once this is completed, Xcode should already be launching a new project that is ready to work on.

5. Add functionality

You now have the basics of a backpack, but it still does not contain anything.
Delete the “ReplaceMe.swift” file and add a new file and write the appropriate code inside

6. Check the pod spec file

Before making any changes, we need to verify the pod spec file.
Enter the command below:

You will receive errors as below:

-> RandomNumberGenerator (0.1.0)

   - WARN  | summary: The summary is not meaningful.
   - WARN  | url: There was a problem validating the URL https://github.com/<GITHUB_USERNAME>/RandomNumberGenerator.

[!] RandomNumberGenerator did not pass validation

You can use the `--no-clean` option to inspect any issue.

To fix this, we need to add more information to the summary and specify the git repo URL for the pod homepage.

7. Make changes to Git

Launch / build an application once. Once you achieve success, it’s time to push code.
You can use a console or any other tool (for example SourceTree) to push code

Also, push the tag to about 0.1.0

Install a pod in your project

You should now be able to set up your directory by editing your podfile file, adding the source of your private repo to the top and the standard cocoapods cubes.

To do this, create an iOS app (example – PodTest1) using Xcode and open a terminal in the project path

Enter the command below:

After that, you can see another podfile for your project folder

Open the podfile and add our private pod as follows:

Save and close the file.

Now run a command:

After completing the installation, double-click the Xcode workspace to open the project.
Now build and run it, you can access the code from your private library in the app.

Is not it so easy? So, now you have created your first private pod and used your app. You can now leverage the benefits of reusable code on your iOS internal projects using the power of private ponytails.
Happy Coding 🙂

Source

spot_img

LEAVE A REPLY

Please enter your comment!
Please enter your name here