【发布时间】:2012-11-13 20:29:23
【问题描述】:
我有一些从服务返回的 JSON,对于布尔属性,有时该服务将具有 null 而不是 true/false;像这样:
"hide_locations" : null,
我接收这个值的对象有一个属性:
@property (nonatomic, assign) BOOL hideLocations;
我的映射是这样配置的:
RKObjectMapping *retVal = [RKObjectMapping mappingForClass:[self class]];
[retVal mapKeyPath:@"hide_locations" toAttribute:@"hideLocations"];
但是当我执行映射时,RestKit 0.10.3 在这条线上崩溃了:
[self.destinationObject setValue:value forKeyPath:attributeMapping.destinationKeyPath];
在 - (void)applyAttributeMapping:(RKObjectAttributeMapping *)attributeMapping withValue:(id)value
在 RKObjectMappingOperation.m 中出现以下错误:
2012-11-13 09:33:04.352 Tests[73816:5f03] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“[setNilValueForKey]:无法将 nil 设置为键 hideLocations 的值。'
在我看来,像这样成熟的框架并不能更优雅地处理这种情况,这让我觉得很奇怪,所以我不禁认为我配置了一些不正确的东西。如果您有任何见解,我将不胜感激。
【问题讨论】: