ObjC 字典转模型中出现id怎么替换

+ (instancetype)picinfo:(NSDictionary*)dict{    PicModel *picmodel = [[selfalloc] init];    [picmodel setValuesForKeysWithDictionary:dict];returnpicmodel;}

单纯的运行setValuesForKeysWithDictionary是必然core的

这时只需要重写- (void)setValue:(id)value forUndefinedKey:(NSString *)key 方法即可

- (void)setValue:(id)value forUndefinedKey:(NSString*)key  {

if([key isEqualToString:@"id"])

self.ID = value;

}

并把声明 中的id改为userid

@property(nonatomic,strong) NSString *ID;

这样一来执行程序快速,还省去了不少手工代码。

你可能感兴趣的:(ObjC 字典转模型中出现id怎么替换)