以下代码从我的服务器接收 JSON 响应,该响应由一组元素组成,每个元素都有一个“created_at”和一个“updated_at”键。对于所有这些元素,我想删除为这两个键设置的字符串中的单个字符(冒号)。
- (void)objectLoader:(RKObjectLoader*)loader willMapData:(inout id *)mappableData {
// Convert the ISO 8601 date's colon in the time-zone offset to be easily parsable
// by Objective-C's NSDateFormatter (which works according to RFC 822).
// Simply remove the colon (:) that divides the hours from the minutes:
// 2011-07-13T04:58:56-07:00 --> 2011-07-13T04:58:56-0700 (delete the 22nd char)
NSArray *dateKeys = [NSArray arrayWithObjects:@"created_at", @"updated_at", nil];
for(NSMutableDictionary *dict in [NSArray arrayWithArray:(NSArray*)*mappableData])
for(NSString *dateKey in dateKeys) {
NSString *ISO8601Value = (NSString*)[dict valueForKey:dateKey];
NSMutableString *RFC822Value = [[NSMutableString alloc] initWithString:ISO8601Value];
[RFC822Value deleteCharactersInRange:NSMakeRange(22, 1)];
[dict setValue:RFC822Value forKey:dateKey];
[RFC822Value release];
}
}
但是,该行[dict setValue:RFC822Value forKey:dateKey];
引发了一个NSUnknownKeyException
带有 message 的问题this class is not key value coding-compliant for the key created_at
。
我在这里做错了什么?我的主要问题可能是我对这个 inout 声明不太满意......