The two main architectures in iOS and their pros and cons

Source: Internet
Author: User

The developers of any program should be familiar with the program architecture. The architecture of a program has a very important role to play in this program. Today, let's look at the two main program architectures used in iOS development. In this process, we mainly unfold in the form of examples.

Let's look at the first architecture: as shown in:

The main principle of the architecture of this program is to create a navigation controller to control the switching between pages. This architecture typically takes the main interface as the root view controller of the navigation controller . In the desired program architecture, the main interface manages four interfaces: interface, Discovery interface, contact interface, about my interface. If the program is the first time to run, enter the User Guide interface, and then enter the login screen, enter the account name and password to enter the main interface. There are two situations in the About me interface: 1. After exiting the login in the program's About me interface, the next time you enter the program, you should enter the login screen and enter the account name and password to enter the main interface. 2. There is this requirement to view the User Guide interface in the About me interface.

The idea of the architecture of this program is to include the header file of the interface when it is used. Use the navigation controller to push this interface to press the stack to achieve the switch between pages. When the main interface needs to be used, the Poptoroot realizes the switch to the main interface.

But what are the drawbacks of this architecture:

1. Let's analyze the entire program. Because the main interface is the root view controller of the navigation controller. Because the root view controller is not allowed to stack in the navigation controller's stack, this is determined by the characteristics of the navigation controller. In this architecture, the main interface contains four interfaces. The home page of the host controller is too large and has been running in memory for a long time while the program is running or running in the background, which can cause significant memory overhead.

2. Whenever the program is re-entered, you need to update the status in the main interface. For example, when I quit on my interface, the next time I log in again, if I don't update the state of the main interface. Will go directly to this interface about me. This demand is not the state we want.

Let's look at the second architecture .

  

It is clear that this architecture will be more clear and clearer. Let's take a look at the principle of this program: The architecture of this program is to manage the switch between pages by creating a master controller that inherits from the NSObject object. We all know that a program typically has only one window, which allows you to switch between different pages by changing the window's root view controller.

Similarly, there is no perfect architecture, only the more suitable. Let's look at the pros and cons of this architecture.

1. Let's start with the pros. Obviously, the idea of this program architecture is very clear. When switching between complex pages, there is no need to repeatedly include a header file that toggles the page. During the execution of the program, it is necessary to find out exactly who is the window's root view controller to enable switching between different pages. Of course, the main task of this architecture is to find ways to encapsulate the main controller method.

2. Let's take a look at the drawbacks of this architecture: there is no navigation controller, there is still a host controller (Mainviewcontroller) in memory, but careful consideration will find that this architecture will repeatedly request memory and destroy other pages managed by the host controller. The same main interface contains many pages. This will also affect the execution efficiency of the program.

So, on top of that, the second architecture is generally used in arc environments.

For the execution efficiency of the program, a good solution is to make the main controller (Mainviewcontroller) into a singleton object, the single object in the whole process of running the program only one object, to avoid the use of re-application of memory caused by unnecessary overhead. The other three interfaces generally make them into @property categories. This ensures that when a new page is re-loaded, the memory will be determined first. If you're there, just take it out.

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.