iOS Object-oriented modeling: MVC (OC Foundation)

Source: Internet
Author: User

    • 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)

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.