1. Sources of demand

APP business is increasingly complex, including multiple product lines, some of which have the same process, some of which are inconsistent. Developers of different product lines are all developed in the main project, which enables the whole project to run. Code management, parallel development efficiency, branch management and on-line time are all limited.

2, I met

It is suitable for large projects with multiple and complex business lines. Bloated and complex projects can be decomposed into independent functional modules or components according to functions or attributes, and then arbitrarily organized into a project with complete business logic according to the needs of the project and business in a certain way.

But componentization has its own disadvantages:

  • Serious code coupling
  • Depend on the serious
  • It is difficult to integrate other apps into a product
  • Projects are complex, bloated, huge, and take too long to mutate
  • Integration testing is difficult
  • To kay, the developer, you can only use the same development model

Advantages:

  • Clear project structure
  • Clear code logic
  • Small resolution size
  • Rapid integration
  • Ability to do unit tests
  • High code utilization
  • High iteration efficiency

3. Necessary tools

CocoaPods: Components exist in the form of each POD library. We combine components by adding and installing each component in the way of cocoaPods. We need to make cocoaPods remote private library and send it to the company’s GitLab so that the project can be downloaded by POD

Git: basic command

  • git init
  • git add README.md
  • git commit -m “description”
  • git remote add origin url
  • git push -u origin master

Create a remote private library:

  • pod lib create projectname
  • echo “# test”>>README.md
  • git init
  • git add README.md
  • git commit -m “description”
  • git remote add origin url
  • git push -u origin master
  • vim CoreLib.podspec
  • Git tag ‘1.0.0’
  • pod lib lint –allow-warnings –no-clean
  • pod repo add WDSpecs [email protected]/CoreLib.git
  • pod repo push WDSpecs CoreLib.podspec –allow warnings

4. Module splitting

    1. Basic components: macros, common categories, and utility classes that are not dependent on lines of business
    1. Functional components: sharing, rotation, statistics, positioning, push, can be quickly integrated later
    1. Business components: login, real name, message, etc
    1. Middleware: Handles communication, parameter passing, and callbacks between components
    1. Host engineering:

5, iOS compatible with SWIFT

Podfile file to add use_frameworks!

6. Communication between components

Using the message sending mechanism, each startup loads the routing configuration file through

((id (*)(id, SEL, NSDictionary *)) objc_msgSend)((id) cls, @selector(load:), param);
((void(*)(id, SEL,NSDictionary*))objc_msgSend)((id) vc, @selector(callBack:), param);
//or
[vc performSelector:@selector(load:) withObject:param];
[vc performSelector:@selector(callBack:) withObject:param];
Copy the code

To send messages, removing the interdependence between modules

7. Componentized resource loading

Image, NIB, local other resources to load