Understanding of the iOS front-end framework

Source: Internet
Author: User

iOS front-end architecture design, I understand the meaning is that the use of what kind of pattern or structure of the code is how the various classes work together, or the structure of the file storage, the different classes in the end how the division.


There are a lot of foreign language on the iOS architecture of the article, but the English proficiency is limited, only to see a few translated articles. MVC, MVVM, Viper, and so on a few can not remember the name, but no matter what the structure of the sense of understanding is not very deep, the specific code when there is no point too clear, is how convenient how to come. Finally led to a number of refactoring, but after the completion of the refactoring, after a while to look at the code or feel the structure is not clear enough, the relationship between the various classes is confusing. Now the project is also mixed with a variety of modes, such as simple page is the structure of MVC, some of the complex interface is MVVM, writing this article today, not to share the experience of the framework design, but to see what is now the understanding of the framework of the deviation.


650) this.width=650; "src=" Https://nzw3d6nir.qnssl.com/images/2013/03/model_view_controller.png "width=" 879 " height= "252" alt= "Model_view_controller.png"/> cited a familiar picture of MVC


Mvc,m is the model used only to store data, but some people put the model-related algorithms in the model, the final model in addition to a few properties, there are several related methods. V is the view, Apple's official demand for MVC is the most cautious is that view can not hold any data, this is also reasonable, decoupled. C is the controller, responsible for business logic, including data requests, interface logic and so on. Such a layering will lead to a more common result, that is, the code in C is too large, resulting in the whole class is not easy to understand, inconvenient later maintenance, single-person feel, this is not the wrong MVC, but we often misunderstood the design of the original idea of MVC, Apple thought we can do it, but ..., Recently read an article that makes sense and is vindicated by MVC: The misunderstood MVC and the deified MVVM(which seems to be written by the Great God Tang Qi).


Personal feelings most frameworks tend to be a principle, a single function principle, a class that is responsible for a function, but the more detailed the framework, the more redundant the project is. But some simple division of labor is still necessary, as we usually do, each network request to be taken out separately, encapsulated into a direct callback result class, like afnetworking, data cache, such as a separate list; TableView's DataSource is listed separately. This writing basic work done, feel the use of what architecture is irrelevant, see the frame meaning are similar, are assigned to each module corresponding functions, the above work in addition to some data and page logic, there is basically not much to deal with. When this layering is complete, the controller is about data and page logic, and some event monitoring, Tang Qiao Great God's proposal is the data and page to establish a separate class processing, and finally led to the controller only need to be responsible for assigning different monitoring events, In fact, MVC is not too much of a problem.


650) this.width=650; "src=" Http://gracelancy.com/assets/post/arch0.png "width=" 934 "height=" 368 "alt=" arch0.png "/ > Borrow a picture of MVVM


MVVM, not understanding too thoroughly, interested can look at: Ape Question Bank IOS client Architecture Design (this article from the ape Question Bank is in favor of MVVM, but Tang Qi is also the ape Question bank, Tang Qiao favor is MVC, do not know whether they will fight up), my feeling is: M, Model,v,view (including Uiview,uiviewcontroller,), Vm,viewmodel (classes that store data, handle page data logic, and event snooping), in addition to the basic work I just said, The key step is to ViewModel and view bindings, and the rest is to do all the controller's things, if not simplifying seems to cause the code too complex problems. My understanding of this division of labor does not feel much effect, later understanding more profound time, then to detailed decomposition (is improved MVVM, looking more reasonable).


Viper an article on Cocoachina, this framework layering is more detailed in this article: use Viper to build iOS apps .

"VIPER is a program that creates a concise architecture for IOS apps. VIPER can be the initials of a view, an interaction (Interactor), a display (Presenter), a solid (entity), and a route (Routing). A concise architecture divides the logical structure of an application into different layers of responsibility. This makes it easier to isolate dependencies, such as databases, and to test the interaction at the boundary between layers more easily: "

650) this.width=650; "src=" Http://www.cocoachina.com/cms/uploads/allimg/140703/8370_140703100012_1.jpg "width=" "/>

The focus of the Viper architecture:

  1. The interaction represents a separate use case in the application. It has business logic to manipulate model objects (entities) to perform specific tasks.

  2. route: The path between the screens is defined in the wireframe (wireframes) created by the interaction designer. In VIPER, the route is handled by two parts: the display and the wireframe. A Wireframe object includes parts such as Uiwindow,uinavigationcontroller,uiviewcontroller, which is responsible for creating a view/view controller and assembling it into a window.

After reading Cocoachina's article, a bit does not understand is the routing function, may be responsible for the interface between the switch use.

viper is broadly described above, but it feels more and more like Tang Qi's improved structure after MVC, such as being responsible for a particular business logic, and the functions that are specifically responsible for manipulating an interface are quite similar to the improved MVC architecture.

So the final feeling is that all architectures follow one principle: a single function. Extracting something complex, such as requests, business logic, interface logic, data storage, and so on, each class is responsible for a single function, and finally makes the whole project more reusable and more efficient. But any conclusion is not certain, for example, in the interface display and interactive relatively simple project, the finer division of labor, the larger the workload instead. Even in a project, a simpler interface can be handy for how to (personally understand).

This article from "Yunsankai" blog, declined reprint!

Understanding of the iOS front-end framework

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.