Preface: This article mainly describes the making process of the private libraries, as well as in some problems and solutions in the process of using, mentioned componentization relates to the small private library will have to think of the pods (componentization is not limited to, of course, combining with the private library use, can also be made into static library or more target development, here only on private library, A later article on componentization and private libraries for componentization.)

As the name suggests, a private library is a library that does not want to be exposed to the public. It can also be said that it is only for the use of companies or individuals. The common third-party library management method is cocoapods. Can also be understood as a public library to address https://github.com/CocoaPods/Specs in terminal input pod repo can see there is a master, this is what we are at the time of installation cocoapods, create index on the local library, By default, third-party library files will be retrieved from the local index library first. If the local index library is not available, it will be retrieved from the source address. This is why we were slow to pod install the first time. Pod update XXX –no-repo-update Ok, no more nonsense, let’s get to the point (for easy copy and view, I will add the operation diagram and the corresponding command)

One: preparation

1. Check whether a private database index file exists on the local PC

pod repo

master

2. Create a remote private library index (github as an example)

Since github private library charges, I use public as an example, in fact, it is the same. The common name is xxxSpec

Here we can get the address of a remote index repository, which we will use next

3. Add the local private library index

The terminal runs the pod repo add local index library name Address of the remote index library. The following address is the address of the remote index library. LWPrivateSpec is the name of the local index library

Pod repo (pod repo, pod repo, pod repo, POD repo, POD repo

Two: private library creation

1. Create a remote repository

Methods are the same as index library creation, which will not be described here

2. Download the remote kulla to the local PC

Select a path to clone the remote repository to the local Git clone location

For testing purposes, you need to create test projects to facilitate the testing of component functions

3. Create a project

4. Introduce the pod

Go to the project directory and run the following command to create an empty POD file, pod init

pod install

5. Create a PodSpec file

Go to the path of the local repository and run the following command

Pod spec Create pod spec create pod spec create pod spec create

Create a Pod/Classess file in the same path as the. Podspec file.

Subsequent functional modules are placed in the classes file

Three: PodSpec writing and related dependencies

1. Podspec file writing

Open the podSpec file as follows (an excerpt) :

Here are a few points to note:

  • S.name: indicates the name of the library
  • S.v ersion: version number
  • S.s ummary: in this paper
  • S. description: Description section, longer than the abstract
  • Epage: the source address, which is the remote address corresponding to the private library
  • S. license: indicates the license. The default value is generally selected
  • S. Thor: Author name
  • S. platform: Supported platform
  • S.s ource: source
  • S.source_files: indicates the file path
  • S. ramework/s. rameworks: rely on the framework of the system
  • S. dependency: dependency library

When you do this, you’ll see that all the.h,.m files are under the Classes file, and we’ve seen that some third-party file management is layered

Like this there are several libraries, for example, we want to use WXPay, so in podfile you just need to introduce pod ‘YGFunctionComponent/WXPay, so this is how to set up? Here it is:

2. Preparation of layered files

There are three sublibraries, each of which can write its own functionality, and of course can depend on each other, which we’ll talk about later

It’s important to note that do and end should be paired, otherwise we’ll get an error when we validate. You may have noticed that we can set dependencies in the child library as well. Another thing to note is that the parent library’s source_files setting is either removed or changed. {h,m}. For example, if we want to have a header file XXX. H in the parent library, we need to set it to Pod/Classes/ XXX

The import structure is as follows:

3. Dependencies between sub-libraries

For example: I have a library of Utils in LWFunctionComponent that I use in the LocationTool. How do I set this library?

Xx.dependency "Library name/sublibrary name"

4. Dependencies between private libraries

Same as dependent third party libraries. “private library name

5. Validate the process

The first step is to commit to a remote git add with the tag value.

git commit -m "xxx"

git push

Git tag XXX git tag XXX must be the same as podspec or an error will be reported

git push --tags

5.1 Verifying Pod Lib Lint locally

5.2 Remotely Verifying pod Spec Lint

6. Add to private library index

Pod repo push Local private index file name library name. Podspec

Of course, if you just write above you will find that there are many problems, in the third point I will list some common problems and solutions

Three: verification process problems and their solutions

  1. Git tags must be the same as podSpec tags
  2. Warning causes problems, you will find a lot of -warn beginning when submitting, if you follow thepod spec lintorpod lib lint, then there must be an error, this time just need to add--allow-warningsCan solve
  3. Rely on third-party libraries to report errors, just add--use-librariesCan solve
  4. Private libraries rely on errors that cannot be found in private libraries, usually by default from the master or official spec source addresshttps://github.com/CocoaPods/SpecsTo find the dependent library file, and private library is not found, so the solution is as follows:--source= private library source address, official library source addressCan be

Note: add private indexes to the libraries using the –use-libraries –allow-warnings flag

Conclusion: I have been writing for more than two hours. I really don’t want to take screenshots of the last problem and solution module. If necessary, I will fill it later

In addition, if you submit public repository open source, of course need to register a trunk, the registration method is as follows:

Pod trunk register ‘author name’ –verbose The author name is the same as s.thor set in podSpec 2. Go to the mailbox to verify