iOS latest component implementation

The implementation of component warehouse is generally divided into two steps. The first step is to establish a local warehouse. After the local warehouse is created, it needs to check whether its format and content are compliant. After the detection is passed, the second step is to associate git to the remote warehouse. It will not be completed until the address can be imported.
Note: According to the development specifications, the file names in the components comply with the Swift namespace and are not required to have a prefix. However, the component name must have a prefix. The prefix is ​​designed by the business itself, followed by the component name. The component name must reflect the function of the component.

1. Local warehouse

1. Create a local warehouse

1. Enter the component folder. It is recommended to put all components into one folder for easy use later.

example:

cd /Users/xxx/Desktop/HandUniversity/Module

2. Create module

At this time, it will be faster and simpler for us to use script commands to create. The commands are as follows:

pod lib create HURouter

Wait for the input to be completed, press Enter and wait. Among them, HURouter is a component name you customized, which is one of your components or business modules, and then generate a pod project template according to the prompts. As shown below:
Insert image description here

3. Replace the file and put the required files in it.

Insert image description here

4. Execute the pod command and introduce the project

pod install

At this point, our file can be seen to have been introduced into the Example project
Insert image description here

5. Configuration information

Execute build RUN to check whether the project can be tested and run independently. If there are any problems, fix them. If there are no problems, you can configure the Podspec file. This is a critical step and must be configured according to regulations. The configuration file location and information are as follows:
Insert image description here

2. Use local warehouse

1. Introduce pod

First, open our main project App and configure the local warehouse in the Podfile file. as follows:
Insert image description here

2. Integration

Execute pod command

pod install

When the following situation occurs, it means that the local warehouse has been built and needs to be associated with the remote end.Insert image description here

2. Connect to the remote end

1. Create a git warehouse, using gitLab as an example

Insert image description here
It is recommended to add a prefix to the component name. The code does not need to be added if it follows the swift namespace, but the component library must be differentiated. HU is HandUniversity, followed by our component library name. The name must be representative and can intuitively determine its functionality. Don’t mess with things and follow naming conventions. Use a dash in the address to keep the other ends consistent.

2. Git association

1. Initialize git

git init

2. Add code

git add .

3. Configuration upload information must comply with git upload specifications

git commit -m "feat:第一次添加路由组件"

4. Associate with remote warehouse

git remote add origin https://developer-center.wxhand.com/gitlab/front_ios/hu-router.git

5. Submit to remote master

git push origin master

6. Check whether the upload has been completed

Insert image description here

7. Component version control

Components need to provide external dependencies. So we have to do one more step, which is to modify the podspec file. We can perform version control and upgrades based on different tags corresponding to different podspec files. implement:

git tag 1.0
git push --tags

Refresh gitLab and you will see an additional tag branch:
Insert image description here

3. Verify whether the Podspec file and project are compliant

Errors in coding issues and configuration issues will cause verification to fail. At this time, the terminal returns to the root directory of the component and executes:

pod lib lint --verbose --allow-warnings

If the component depends on a component implemented by ourselves, use the following method to verify

pod spec lint --verbose --use-libraries --allow-warnings --sources='https://developer-center.wxhand.com/gitlab/front_ios/hu-private-podspecs.git,https://github.com/CocoaPods/Specs.git'

At this time, the script will automatically help us verify. After the execution is completed, if there is any problem, modify the relevant information, then execute the verification command, and wait for the result:
Insert image description here
xxx passed validation. appears, which means that our component has been configured successfully.

4. Submit components to the remote warehouse group

At this time, when we import, we can only use the path. If we want to use it directly, we can only import the direct path. This is still very troublesome, so we need to import it into the local index library. Execute
:

pod repo push HUPrivatePodspecs HURouter.podspec --allow-warnings

Wait for a while. If the following happens, it means success.
Insert image description here
At this time, we can use it directly. Add the repo address to the project, and then the pod method can be introduced normally.
Insert image description here

Guess you like

Origin blog.csdn.net/weixin_38201792/article/details/132187700