有没有更短的方法来做到这一点?
我用一些谓词获取所有核心数据对象,然后使用 RestKit 和定义的映射将它们解析为 JSON……我仍然想使用 RestKit,但不能做得更简单吗?
- (NSArray *)serializedManagedObjectClass:(Class)managedObjectClass updatedSinceRevision:(long long)revision {
NSArray * managedObjects = [managedObjectClass MR_findAllSortedBy:@"createdDate" ascending:YES withPredicate:[NSPredicate predicateWithFormat:@"revision > %lld", revision]];
NSError * error = nil;
NSMutableArray * serializedObjects = [[NSMutableArray alloc] initWithCapacity:[managedObjects count]];
for (NSManagedObject * managedObject in managedObjects) {
id object = [NSMutableDictionary new];
RKObjectMappingOperation * op = [RKObjectMappingOperation mappingOperationFromObject:managedObject toObject:object withMapping:[self.objectManager.mappingProvider serializationMappingForClass:managedObjectClass]];
BOOL success = [op performMapping:&error];
if ((success) && (error == nil) && (object)) {
[serializedObjects addObject:object];
} else {
ALog(@"Serialization problem with %@, possible error %@", managedObject, error);
}
}
return serializedObjects;
}