iOS 模型之中添加非空的方法
- (id)initWithDict:(NSDictionary *)dict
{
self = [super init];
if (self) {
[self setValuesForKeysWithDictionary:dict];
self.max = [NSString stringWithFormat:@"%@", dict[@"max"]];
self.average = [NSString stringWithFormat:@"%@", dict[@"average"]];
self.stars = [NSString stringWithFormat:@"%@", dict[@"stars"]];
self.min = [NSString stringWithFormat:@"%@", dict[@"min"]];
}
return self;
}
- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
}
-(id)valueForKeyPath:(NSString *)keyPath
{
return nil;
}
+ (id)ratingModelWithDict:(NSDictionary *)dict
{
return [[self alloc] initWithDict:dict];
}
1