iOS Development Basics-Nine grid coordinates (6)

Source: Internet
Author: User

Continue to optimize the code in IOS development Fundamentals-Nine (5).

Optimization thinking: The dictionary to model part of the data processing operations also get to the model class to achieve, will be Viewcontroller class implementation of the application method to move to the Wjqappinfo class implementation.

Instance Code

Add an out-of-the-box interface to the WJQAppInfo.h , which returns a well-handled model array, defined by the following method:

+ (Nsarray *) Appinfoarray;

The implementation code is as follows:

1 //WJQAPPINFO.M. Move the data Processing section to the model class for processing2+ (Nsarray *) Appinfoarray {3NSString *path = [[NSBundle mainbundle] Pathforresource:@"Data"OfType:@"plist"];4Nsarray *arraym =[Nsarray Arraywithcontentsoffile:path];5     6Nsmutablearray *appinfoarray =[Nsmutablearray array];7      for(Nsdictionary *dictinchArraym) {8 [Appinfoarray addobject:[wjqappinfo appinfowithdict:dict];9     }Ten     returnAppinfoarray; One}

At this point, the viewcontroller View Controller no longer needs to be concerned with the internal details of the data processing, only the interaction between the model and the view. To modify the properties of an apps getter Method:

1 // VIEWCONTROLLER.M 2 -(Nsarray *) Apps {3     if (!  _apps) {4         _apps = [Wjqappinfo Appinfoarray]; 5     }6     return  _apps; 7 }

Reference Blog: iOS Development UI-MVC from the gradual optimization of code

Instance code: HTTP://PAN.BAIDU.COM/S/1DEI2QE9

iOS Development Basics-Nine grid coordinates (6)

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.