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