IOS creates a private library based on cocoaPods, and develops the idea of componentization

For versions above xcode9, the support for git is better. Here we choose to use git for code version control. To use git, we quickly thought of github, but sadly, the computer I use can only connect to the local area network and cannot access the github official website. You can use gitblit to create an internal git server, which is very simple. But the author intends to use the code cloud as a git repository for code hosting. Specific steps:

1. Preparation

    1.1. Familiar with the operation of git

    1.2. Download the pod-template project on github through the mobile phone network (except for computers that can access github), and upload this project to the code cloud repository using git, so that you can use pod lib create to create pod third-party components later

    Uploaded git commands: git add, git commit, git push, etc.

2. Create a warehouse named Specs

   2.1. This warehouse is mainly used to save the podspec file of the component. Later, we will talk about the synchronization of the podspec file of the local warehouse to the Specs warehouse. This file is the instruction document for cocoapods to download third-party components.

    2.2. Add the Specs repository to the pod repository list

    pod repo add XXX (repository name) http://xxxx/xxx/Specs.git , then use pod repo to view the list of pod repositories

3. Create local third-party components (such as AFN-like frameworks)

    pod lib create xxx (component name) will be created through the pod-template project template in github by default, you can make your own through --template-url=URL

Warehouse address, the first step I have put the pod-template on git on the code cloud gitee, the project structure created by the command, as shown on the right, we can define the IOS we want

The class file is placed in the location of ReplaceMe.m, and the import call can be made using pod install, but at this time the pod components we created ourselves are placed in our local project, I

We need to put it on the gitee code cloud repository.

4. Create a third-party component warehouse

    4.1. After creating the warehouse, use the git command to submit the local third-party component to this warehouse (ComponentDemo). At this time, you need to set a Tag for the component

    git tag xxx (version number), git push --tags https://xxxx/xxx/ComponentDemo.git

    4.2. Create the ComponentDemo/0.1.0 file path in the local warehouse (Mac path: /Users/username/.cocoapods/repos/Gitee, created in the second part), and put the ComponentDemo in the local third-party group we created Copy the .podspec to the 0.1.0 folder and temporarily modify the following bubbles.

After modification, use pod spec lint to verify the validity of the file. If it passes, you can use pod Search ComponentDemo to search for our component. We also need to submit this podspec to the Specs repository.

5. Use cocoapod to import in xcode

source 'https://xxxx/xxx/Specs.git'

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324376633&siteId=291194637