I have been developing iOS for many years, today I will talk about my iOS architecture ideas, as well as my own architecture, I use MVVM thinking architecture. What is the architecture

Architecture: the design of software development,


Relationships between classes, between modules, between clients and servers.





Commonly heard architectural terms: MVC, MVP, MVVM, VIPER, CDD, three-tier architecture, four-tier architecture, etc.





Interface presentation layer: encapsulates common components, business UI, and so on. Business logic layer: business by business. Data holding layer: business requests, data storage, and so on. Infrastructure layer: Used to encapsulate network requests, utility classes. Third-party plug-in layer: Manage third-party libraries through CocoapDS, including wechat, Alipay, QQ, and common third-party libraries.

Since I am based on MVVM ideas to architecture, that MVVM exactly how to achieve?


Schematic diagram of MVVM


The communication relationship of MVVM is as follows: 1.View and Model do not communicate directly. 2. The ViewController does not communicate directly with the Model. 3. The View only relates to the ViewController/View Model. 4.Model communicates only with View Model.

Model: business logic processing, data control (local data, network loaded data). View: Displays user visible View controls and user interaction events. ViewModel: Is the view data layer that the organization generates and maintains. In this layer, the developer transforms the Model data obtained from the back end and performs secondary encapsulation to generate the View data Model that meets the expectation of View layer usage. ViewController: controls the interface life cycle and service switching.

Advantages of MVVM Low coupling: Views can be changed and modified independently of model, a viewModel can be bound to different Views, reusability: you can put some view logic in a separate development: Developers can focus on business logic and data development viewModels, and designers can focus on page design testable, which can be tested against the viewModel

The downside of MVVM is that bugs become difficult to debug, and when an exception is encountered, it could be a view problem or a Model problem. Data binding allows bugs to spread quickly elsewhere, making it harder to pinpoint the original problem. Converting data requires more memory. Mainly from inside the array, item again contains the array. Multiple nested types. It takes a lot of conversion to make it a view. The standardization of data types returned by API is highly required to improve the reuse rate of ModelView, otherwise type explosion is easy to occur and maintenance costs are increased.