preface
With the increase of the project volume, the number of developers increases. For better cooperative development, we often need to divide the large project into small projects, which has the following advantages:
- To speed up the development efficiency, if we carry out iterative development in a large project, the compilation time is often very long. If you develop a module with a relatively deep entrance, during development and debugging, you only modify the LOCATION of the UI interface, re-compile and run, and then dot and dot to the corresponding interface, often waste a lot of time. After the module is separated into a single executable project, the compilation and debugging time is greatly reduced.
- Parallel development: Since each sub-project can carry out separate version control, the main project can rely on the sub-project of the lower version when the sub-project is developing new functions, without affecting the operation of the main project.
- Improved division of labor, different sub-projects can be taken charge of by different personnel or even different teams.
- Code sharing, different APP projects can easily and quickly reuse components.
Let’s create a child project using POD and introduce it into the main project using POD
steps
Create a subproject
- use
Xcode
A new project is calledHomeModule
- Often we will create another Demo project to use as an example. In this case, we can create a directory named HomeModule
HomeModuleDemo
The engineering of - For convenience, create a directory named HomeModule
Classes
“Folder, put all the code classes that need to be exported in this folder, create aResources
Folder, save the resource files to be exported in this directory - CD Go to the HomeModule project directory and enter the command
pod spec create HomeModule
This command will be generated in the directoryHomeModule.podspec
File, this file is actually the description of the project, such as the project name, hosting address, which files need to export, etc
Here is an example diagram of a directory that goes this far
-
Now you can host the project in an online Git repository
-
Open up HomeModule. Podspec and make some edits. Here are some common configuration edits
Pod::Spec.new do |s|
s.name = "HomeModule"
s.version = "0.0.1"
s.summary = "HomeModule is a ...."
s.homepage = "https://github.com/xxx"
s.license = "MIT"
s.author = {
"xxx"= >"[email protected]",
}
s.source = { :git => "https://github.com/xxx/HomeModule.git", :tag => "#{s.version}" }
s.source_files = "Classes/*.{h,m}"
s.resources = "Resources/*.png"
s.requires_arc = true
s.ios.deployment_target = "7.0"
s.osx.deployment_target = "10.9"
s.watchos.deployment_target = "2.0"
s.tvos.deployment_target = "9.0"
s.frameworks = 'UIKit'
s.dependency 'Masonry'.'~ > 0.6.2'
end
Copy the code
The following points are worth noting
s.source
Is the project hosting addresss.source_files
The files that need to be exported are the files that will be introduced into your project by other projects eventually through POD, which embodies the benefits of POD. When we develop components, we can be a complete iOS project, which can be independently developed and run debugging. When using POD for others, we only need to export the core filess.resources
The resource file to be exported- If you have a secondary directory under Classes and Resources, you might want to write it like this
s.source_files = "Classes/**/*.{h.m}"
S. lesources is written the same way s.frameworks
The system libraries you depend ons.dependency
Other third-party POD libraries that you rely on
- Develop the HomeModule module to add new functionality
- Push the new HomeModule code to the Git repository and create a tag 0.0.1
Create a private Cocoapods Specs repository
This repository is used to host our own podspec files, such as HomeModule. Podspec in this example, such as shopcartModule. podspec…
Cocoapods official spec warehouse is https://github.com/CocoaPods/Specs, a lot of we always use third-party libraries such as AFNetworking podspec file hosting in the warehouse, When we first use cocoapods this warehouse will be cloned to the local user/XXX /. Cocoadpos/repos/master, you can enter this directory, you will find every podspec file for every version of the library in it, When we search the third repository through pod Search, we are actually searching this directory. Sometimes some third-party libraries have released a new version, but we still find the old version because the library has not been updated.
The following is a clone to the Cocoapods official Specs repository:
pod repo list
master
- Type: git (master)
- URL: https://github.com/CocoaPods/Specs.git
- Path: /Users/geforceyu/.cocoapods/repos/master
Copy the code
By the way, pod Update and POD Setup are very slow, and both commands will update the repository. You can change the url of the master repository to the official cocoapods spec image source. For details, see Tsinghua University Software Source
Now that we know about the official Spec repository, we can start creating our own spec repository.
- Create an empty repository called xxxPodSpecs directly on GitLab or Github
- Clone the repository to local
.cocoapod/repos/xxxPodSpecs
, of course, using the POD command line tool,pod repo add xxxPodSpecs https://github/xxx/xxxPodSpecs.git
, and then run the command againpod repo list
You can see that our private spec repository is in the column. - Host our homemodule. podspecs to the private spec repository we just created by CD to the homemodule. podspec directory
pod repo push xxxPodSpecs HomeModule.podspec
In this case, pod will perform a check, usually with some warn, which you can resolve, if you do not want to resolve directly ignore, executepod repo push xxxPodSpecs HomeModule.podspec --allow-warnings
But if it is an error, it cannot be ignored. By the way, when I use pod 1.5.3, I will report an error caused by a bug, which can not be solved. I just need to upgrade to the latest version of POD, which only needs to be executedsudo gem install cocoapods
Will do. If you want to switch between multiple pods, please refer to this articleSwitch between multiple versions of CocoaPods
3. Integration of main projects
- Open our main project
podfile
File, add two lines to the header
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/xxx/xxxPodSpecs.git'
Copy the code
You can add a pod reference home Max later
pod 'HomeModule'.'0.0.1'
Copy the code
You can see that one is the official specs repository and one is our private spec repository, because our own homemodule. podspec file is hosted in the private xxxPodSpecs repository. If we don’t add our own private spec repository source, When pod install, search for HomeModule. Podspec in the official spec repository.
4. New version release
As we continue to develop new functionality for the subproject HomeModule, we will need to update our version as follows
- Push the new HomeModule project code to the Git repository and create a 0.0.2 tag
- Change the s.sion of HomeModule. Podspec to 0.0.2
- CD to the HomeModule. Podspec directory
pod repo push xxxPodSpecs HomeModule.podspec --allow-warnings
- Master of engineering
podfile
Updated to
pod 'HomeModule'.'hundreds'
Copy the code
- Main project execution
pod install
extension
Demo Project Configuration
Usually we will use a demo project to show others some usage of the library. First we need to integrate our HomeMoudle with the demo project via pod
cd
å°HomeModuleDemo
Directory, executepod init
To create apodfile
. The editorpodfile
File to addHomeModuel
The introduction of
target 'HomeModuleDemo' do
pod 'HomeModule', :path => '.. / '
end
Copy the code
Here we pass :path => ‘.. /’ just point to the local homemodule.spec address.
pod install
- Open the
HomeMoudleDemo.xcworkspace
To start writing sample code.
thank you
Good, approximate operation steps with respect to these, in the article which place is not detailed enough perhaps wrong, welcome each see an officer to point out, thank ð