iOS JSModel转化过程中含有id属性解决办法

来源:互联网 发布:微信聊天记录迁移 mac 编辑:程序博客网 时间:2024/05/29 14:42

在和后台的交互过程中,数据模型中有可能会出现id属性,
正常情况下我们是这样子书写

@property (nonatomic,strong) NSString *id;

这个是系统属性,会冲突产生崩溃。所以我们需要给他一个新的名字NewId;

@property (nonatomic,strong) NSString *NewId;

这样子是接收不到值的,还需要重写下面这个方法

- (void)setValue:(id)value forUndefinedKey:(NSString *)key  {    if([key isEqualToString:@"id"])        self.NewId = value;}

第二种方法

+(JSONKeyMapper *)keyMapper{    return [[JSONKeyMapper alloc]initWithDictionary:@{@"id":@"NewId"}];}
0 0