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];

}

posted on 2016-05-30 18:31  哈利波特大  阅读(305)  评论(0编辑  收藏  举报