遵循AFIncrementalStore 的 Github 中的“基本示例”,我将 Rails 属性映射到 Core Data 的attributesForRepresentation:ofEntity:fromResponse:
- (NSDictionary *)attributesForRepresentation:(NSDictionary *)representation
ofEntity:(NSEntityDescription *)entity
fromResponse:(NSHTTPURLResponse *)response
{
NSMutableDictionary *mutablePropertyValues = [[super attributesForRepresentation:representation ofEntity:entity fromResponse:response] mutableCopy];
if ([entity.name isEqualToString:@"Activity"]) {
[mutablePropertyValues setValue:[NSNumber numberWithInteger:[[representation valueForKey:@"id"] integerValue]] forKey:@"activityID"];
}
return mutablePropertyValues;
}
也就是说,我沿着这条路走,后来才知道这没有必要,因为 AFIS 会为您保留该映射。请参阅“增强型托管对象模型”部分下的此套牌。这个播客详细介绍了它。
至于日期转换,在“推特客户端”示例中使用相同的方法完成:
[mutablePropertyValues setValue:[[NSValueTransformer valueTransformerForName:TTTISO8601DateTransformerName] reverseTransformedValue:[representation valueForKey:@"created_at"]] forKey:@"createdAt"];
希望这可以帮助。