How lazy loading is used in the iOS development UI

Source: Internet
Author: User

1. Lazy Loading Basic

Lazy Loading--also known as deferred loading--is loaded when needed (low efficiency, small memory footprint). The so-called lazy load, write is its getter method. The popular point is that in development, when the application needs to use the resources. Do not load resources when the program is started, and then load the resources only when they are running when some resources are needed.

We know that iOS devices have limited memory, and if you load all the resources that will be used in the future once the program is started, you may run out of memory on your iOS device. These resources such as a lot of data, pictures, audio and so on, so when we use lazy loading must be aware of the first to determine if there is already, if not then to instantiate

2. Benefits of using lazy loading:

(1) You do not have to write all the code of the created object in the Viewdidload method, the code is more readable

(2) Each control's getter method is responsible for the respective instantiation processing, the code is independent of each other, loosely coupled

(3) Only when the resources are really needed, then load, save the memory resources.

3. Code examples

For example, the login interface of the application is usually lable and TextField together we customize a Ltview class that contains titlelable attributes and TextField attributes

We can then complete the lazy loading (lazy load) mode by overriding the property's Getter method, using the lazy loading to encapsulate the code in the module, improve the flexibility of the class, and save memory usage for a certain period of time, for the current Ltview, Using the lazy loading means I have provided two sub-views, and if needed, the order call getter method can display the child view, and if not, Ltview is an empty view

Reminder: This is what Apple is advocating. In fact, Apple's iOS system has been used in many parts of the way lazy loading, such as the creation of the controller's view.

How lazy loading is used in the iOS development UI

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.