In the previous [iOS development of componentization (a) : basic remote private libraries use 】 we have actual combat in the basic operation of the remote private libraries, but the component can’t upload finished at one time, with the increase of business, our component may also need to add more things, or to repair some of the problems, this needs us to private library code upgrade and maintenance

Here’s an example of adding a Cache tool to the base component

After the addition we need to update to the remote repository

I. Update the remote warehouse

CD to the location of the local repository

1. Code updates

git add .
git commit -m 'Update Description'
git push origin master
Copy the code

2. Version update

The version update step is very important in preparation for updating the index library

git tag -a 'New version number' -m 'comments'
git push --tags
Copy the code

Check the remote warehouse, the number of labels is already 2, click in, you can see 0.2.0, we will not look at here

2. Modify the description file and update the index base

1. Modify Sepc

Open your xx.podspec file and change the original version number to 0.2.0, which is the same as the previous tag

 s.version = '0.2.0'
Copy the code

2. Verify the remote Spec

pod spec lint --private
Copy the code

Update the index library

Pod Repo push index library name xxx.podspecCopy the code

Third, update use

// --no-repo-update does not update the local index library // Because we have just manually updated ourselves, so we will skip updating pod update --no-repo-updateCopy the code


Fourth, third-party dependence

When our private library needs to rely on a third party to work properly, we need to turn on dependencies in the Spec file, such as the code shown below, which indicates that the current repository needs to rely on AFN and SDWebImage

s.dependency 'AFNetworking'.'~ > 3.2.0'
s.dependency 'SDWebImage'.'~ > 4.3.3'
Copy the code

The modified update operation is the same as above, and will not be repeated here.

However, there is a problem here. If a new partner comes in, the part he is responsible for only needs the Category under LXFBase, and the Cache under LXFBase needs to rely on SDWebImage. At this time, if he pod the whole LXFBase, does he install a third-party dependency library without any reason? So how do you do that?

The solution is to use the sublibrary Subspecs to solve the problem of relying on the entire base component for a small tool

5. Subspecs

What is Subspecs? Here we can search SDWebImage

pod search 'SDWebImage'
Copy the code

As you can see, if we only need to use the GIF feature in SDWebImage, we don’t need to download the entire SDWebImage. Instead, change the ~~pod ‘SDWebImage’~~ to pod SDWebImage/GIF in our Podfile to use this feature alone

So how do we describe a child library

The child library format

s.subspec 'Sublibrary name' doAnother name | | endCopy the code

Since we have separated the sublibrary, we cannot use s.ource_files and s.ependency in this way. We need to specify them separately in the sublibrary, so we just comment out the original s.ource_files and s.ependency. The writing method is as follows

# s.source_files = 'LXFBase/Classes/**/*'
# s.dendency 'SDWebImage', '~> 4.3.3'

s.subspec 'Cache' do |c|
  c.source_files = 'LXFBase/Classes/Cache/**/*'
  c.dependency 'SDWebImage'.'~ > 4.3.3'
end

s.subspec 'Category' do |c|
  c.source_files = 'LXFBase/Classes/Category/**/*'
end

s.subspec 'Tool' do |t|
  t.source_files = 'LXFBase/Classes/Tool/**/*'
end
Copy the code

After the modification, update the index library and component library according to the previous steps

Ps: Verification or upload operations after adding third-party dependency descriptions can be slow because it clones third-party libraries such as SDWebImage. Interested parties can add them after the command--verboseTo see the details

pod spec lint --private --verbose
Copy the code

Let’s try searching again after we have successfully updated the component and index libraries

pod search 'LXFBase'
Copy the code

Now you can install whichever library you like, specifying the child library to install in your Podfile

pod 'LXFBase/Cache'
Copy the code
pod install
Copy the code