标签:
首先看看代码
@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;
属性很多。手工写setvalue太麻烦
+ (instancetype)picinfo:(NSDictionary *)dict { PicModel *picmodel = [[self alloc] init]; [picmodel setValuesForKeysWithDictionary:dict]; return picmodel; }
单纯的运行setValuesForKeysWithDictionary是必然core的
这时只需要重写- (void)setValue:(id)value forUndefinedKey:(NSString *)key 方法即可
- (void)setValue:(id)value forUndefinedKey:(NSString *)key { if([key isEqualToString:@"id"]) self.userid = value; }
并把声明 中的id改为userid
@property (nonatomic,strong) NSString *userid;
这样一来执行程序快速,还省去了不少手工代码。
标签:
原文地址:http://my.oschina.net/wupengnash/blog/466526