- This article forwards to: http://www.cnblogs.com/tmf-4838/p/5294036.html
- Instantiate a class: Extracting a class from a plist file
@interface person:nsobject//Instantiated object (extract Class) @property (Nonatomic, Strong) NSString *name; @property (Nonatomic, Strong) NSString *tel; @property (nonatomic, Strong) NSString *pic;//Traversal Initialization (parameter is dictionary)-(person *) initwithdictionary :(nsdictionary *) dic;+ (person *) Personwithdictionary: (Nsdictionary *) dic; @end
- Using a dictionary as a parameter to the custom constructor
#import "Person.h" @implementation person//Custom constructor-(person *) Initwithdictionary: (Nsdictionary * ) dic {if (self = [Super init]) {_name = dic[@ "name" ]; _tel = dic[@ "Tel" ]; _pic = dic[@ "pic" ];} return self;} Class factory method + (person *) Personwithdictionary: (Nsdictionary * ) dic{return [[Self alloc] initwithdictionary:dic] ; @end
- Storing objects can be more than just pointers to the class
- Instantiate the plist file with the greatest benefit: Data processing creates the corresponding object, and the value manipulation is easy.
- Instantiating objects No need to consider the plist file format, just find the corresponding instance value is OK
- Note:
-
Because all data is instantiated into a collection, if partitioned, Each zone value is starting from 0 \
-
So the use of instantiating objects here is not partitioned and partitioned: Using properties in a collection
- Dictionaries are sometimes more appropriate, Do not think of the set as the preferred (object-oriented idea)
-
//Initialize dynamic collection Self.arrperson = [Nsmutablearray array]; Instantiate the object that the plist extracts out of the class: Assign a value to (NSString *key in self.arrsection) {//Traversal dictionary All value gets a collection by dictionary For (Nsdictionary *dic in Self.dicdata[key]) {//Iterate the collection to get the information (dictionary) of each person object collection store Object (object Storage is not limited to pointers to that class) [Self.arrperson Addobject:[person Personwithdictionary:dic]]; }}//test data exists NSLog (@ "Any object stored by key is name =%@", [self.arrperson[12 ] name]);
iOS Object-oriented modeling: MVC (OC Foundation)