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)