What to do if an ID appears in the IOS dictionary to model

Source: Internet
Author: User

First look at the code

@property   (Nonatomic,strong)  NSString *id; @property   (nonatomic,strong)  NSString  *screen_name, @property   (nonatomic,strong)  NSString *url; @property   (nonatomic,strong)   nsstring *mid; @property   (nonatomic,strong)  NSString *from; @property   (nonatomic,strong )  NSString *created_at; @property   (nonatomic,strong)  NSString *text; @property   ( Nonatomic,strong)  NSString *type; @property   (nonatomic,strong)  nsstring *name;@ property  (Nonatomic,strong)  NSString *user_id; @property   (nonatomic,strong)  nsstring  *width; @property   (nonatomic,strong)  NSString *height; @property   (Nonatomic,strong)  NSString *tag; @property   (nonatomic,strong)  NSString *profile_image; @property   ( Nonatomic,strong)  NSString *image1; @property   (nonatomic,strong)  nsstring *image2;@ property  (nonatomic,strONG)  NSString *image0; 

Many properties. Manual writing SetValue too Troublesome

+ (Instancetype) Picinfo: (nsdictionary *) dict{Picmodel *picmodel = [[Self alloc] init];    [Picmodel setvaluesforkeyswithdictionary:dict]; return Picmodel;}

Simple Operation Setvaluesforkeyswithdictionary is the core of the inevitable


At this point only need to rewrite -(void) SetValue: (ID) value Forundefinedkey: (NSString *) Key method can be

-(void) SetValue: (ID) value Forundefinedkey: (NSString *) key {if ([key isequaltostring:@ "id"]) Self.userid = Valu e;}

and change the ID in the declaration to UserID.

@property (Nonatomic,strong) NSString *userid;

This way, the execution of the program quickly, but also save a lot of manual code.

What to do if an ID appears in the IOS dictionary to model

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.