1
有沒有更簡單的方法來做到這一點?RestKit序列化對象快捷方式
iam提取所有核心數據對象與一些謂詞,然後解析它們到JSON,使用RestKit和定義的映射...我仍然想使用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;
}
這些序列化對象是否使用RestKit發送到服務器? – danielM
是的,還有其他參數 –