Here the main point is to say nsdictionary to the core code of the model object, and need to pay attention to points.
/***
* From processing the data in the plist and returning an array of model objects
*
* @return Nsarray *apps;
*/
-(Nsarray *) apps{
if (_apps==nil) {
The whole path of the past plist
NSString *path=[[nsbundle mainbundle]pathforresource:@ "App.plist" oftype:nil];
Loading arrays
Nsarray *dicarray=[nsarray Arraywithcontentsoffile:path];
Converts all dictionaries inside the Dicarray into model objects and puts them in a new array.
Nsmutablearray *apparray=[nsmutablearray Array];
For (Nsdictionary *dict in Dicarray) {
To create a model object
//initwithdictCustom Object Methods
MYAPP *app=[[myapp alloc] initwithdict:dict];
/***[nsstring stringwithformat:<# (NSString *), ...#>];
[[NSString Alloc] initwithformat:<# (NSString *), ...#>];
[Nsarray arraywithcontentsoffile:<# (NSString *) #>]
[[Nsarray alloc] initwithcontentsoffile:<# (NSString *) #>;**/
/** through here we need to extract a appwith
MYAPP *app=[myapp Appwithdict:dict];
Add to object to array
[Apparray Addobject:app];
}
Assign value
_apps=dicarray;
}
return _apps;
}
#import <Foundation/Foundation.h>/** * Copy:nsstring Strong: General Object Weak:ui Control assign: Basic data type*/ @interface MyApp: Nsobject/** * icon */< Span style= "color: #000000;" > @property (nonatomic,copy) nsstring *icon;* * name */ @property ( nonatomic,copy) nsstring *name; /** * initializes the model object through a dictionary * * @param dic Dictionary Object * * @return already initialized model object *//*instancetype is to make methods of those non-associative return types return the type of the class in which they are located! The benefit can determine the type of object, can help the compiler to better locate the code for us to write problems
Instanchetype and ID comparison 1, the same point can be used as the return type of the method 2, different points ①instancetype can return and the method is the same class type of object, ID can only return an object of unknown type; ②instancetype can only be returned as a return value. Not as a parameter as the ID, such as the following:*/-(Instancetype) initwithdict: (Nsdictionary *) dict;+ (instancetype) Appwithdict: ( Nsdictionary *) dict; @end
Dictionary to model object