Private libraries are now a necessary skill for iOS development. Next, I will use CocoaPods to complete the process of private libraries.

Before we look at the whole process of private libraries, let’s take a look at some of the basics.

Some of the concepts

Repo

Repository is an abbreviation of repository. You can view the local resource library by running the pod repo list command. As follows:

When we use pod Search [PODNAME], we do a library search in the local repository. Note that if your local library is of an older version, you can use pod repo update [NAME] to update the database or the required library, and then perform pod install

Podspec

Spec files are fixed-format index files that describe versions of the Pod library. It includes details about where to get the source, which files to use, the build Settings to apply, and other general metadata such as its name, version, and description.

Working principle diagram

Regardless of what the POD command actually does, let’s look at the big picture: When we use Pod Install in a project, the POD tool will traverse the local repository, find the library in the Podfile, and pull the remote repository code based on the description in the spec file.

steps

1. Configure the index library

Create your own private index library. Code cloud, Github and GitLab are all acceptable. Here, code cloud is taken as an example:

Add a private repository and associate it with your own private repository. Check whether the installation is successful and ready

All the specs passed validation is successful.

2. Configure your own private library

Here use pod official API to create, other ways will not be described. Check out github’s excellent tripartite library and take a look at the directory structure.

Enter pod lib create [NAME] on the terminal and fill in the configuration information as prompted

Enter demo Application on the terminal as prompted. It is recommended to include Demo Application for easy debugging. After executing here, Xcode will be used to open the project. Let’s look at the project catalog

We modify the code in the private library. Update the spec file, save the spec file, and execute pod Install. Because MJRefresh has resource files inside it, add s.resource = ‘HDUIKit/MJRefresh. Bundle ‘to the spec file, as shown:

Next, create an empty repository in the code cloud, associated with the local private repository. Submit the code. I’m not going to bother you here. Basic operations.

3. HandlespecFile,tag

After the private library code is processed, start modifying the spec file.

In addition to the official documentation, you can also refer to third-party spec files for configuration of this file.

After modifying the spec, submit the code and tag it. After submitting the tag, go to the folder containing the spec file and use Pod Spec Lint to check whether the configuration was successful.

Ok, the most important step left is to push the private index file spec to the remote private index library

At this point the construction of the entire private library is complete.

Test, use

You can search our library by command from the terminal

pod search HDUIKit --simple
Copy the code

Create a new project inpodfileSpecify source in the file to use our private library

Refer to the link

Introduction to private libraries

Pod command reference