Follow the whole process of iOS componentization combat I (component library creation)

  • Preface, undertake componentization actual combat a, component library has been created

  • Purpose: Modules (components) can be developed independently under pods without affecting each other

Component development and configuration

1. Add the developed component to the local component template (here is the component template created in the previous article: GTCompDemo)

  • Enter GTCompDemo – > GTCompDemo – > Classes

Add personally developed components to Classes — in this case, the GTPersonTO file 2. Configure the component libraryOpen the Example->.xcworkspace file to enter the demo project

Click on the. Podspec file, add dependency libraries to s.dependency, and add third-party libraries that you need to rely on for component development

Pod ‘Third Party Library’

CD pod Install to the Example directory

cd ~/Desktop/GTCompTest/GTCompDemo/Example
pod install
Copy the code

Componentized multi-module management

1. Create a master project (an empty shell project without writing any code)

My project name here is GT_mainCompCopy the code

2. Add a POD to the project

Terminal CD goes to the project directory

CD ~/Desktop/ componentized actual combat whole process /GT_mainCompCopy the code

Pod initialization

pod init
Copy the code

Pod install component (currently no component in Podfile)

pod install
Copy the code

The following figure shows that the operation is successful

3. Add your own component library to the main project

Re-entering the project found an extra.xcWorkspace file

Double-click to open the. Scworkspace file, select the Podfile file, and add your own, third-party, and local components here

Add remote component libraries

Pod 'GTCompDemo','0.1.0' if the component library is created in the code cloud, Specifies the source address (note that there is index library address) pod 'GTCompDemo', '0.1.0 from' : source = > 'https://gitee.com/xxx/gtcomp-spec.git'Copy the code

Adding local components

# this can be a relative path or an absolute path. / "represents last directory pod 'GTCompDemo', :path => '.. /.. /.. /.. /GTCompTest/GTCompDemo'Copy the code

By importing header files in the project so that we can use our own components, we can add one of our own components to the main project, and we can import other modules in this way for multi-module management

  • Note: Ultimately, use remote components

Why would I use a POD local component if I’m going to end up using a remote component?

Full process 3 of iOS componentization actual combat (multi-module combination)