我现在正在使用restkit。一切都很完美。但现在我想将json映射到我的核心数据库。这是一个(10 MB)的JSON。您可以在here上看到JSON。
我有一个API类,我可以在其中进行映射
-(RKObjectManager *)mapGetItems{
RKEntityMapping* rubriekMapping = [RKEntityMapping mappingForEntityForName:@"Items" inManagedObjectStore:managedObjectStore];
rubriekMapping.identificationAttributes = @[@"itemNum"] ;
[rubriekMapping addAttributeMappingsFromDictionary:@{
@"ItemNum": @"itemNum",
@"ItemDescNl": @"itemDescNl",
@"ItemDescFr": @"itemDescFr",
@"Group1": @"group1",
@"Group2": @"group2",
@"Group3": @"group3",
@"Group4": @"group4",
@"DateCr": @"dateCr",
@"GrpItem": @"grpItem",
@"GrpDesc1": @"grpDesc1",
@"GrpDesc2": @"grpDesc2",
@"GrpDesc1Fr": @"grpDesc1Fr",
@"SalUnitNl": @"salUnitNl",
@"SalUnitFr": @"salUnitFr",
@"LadderQty": @"ladderQty",
@"Netprice": @"netPrice",
@"IsPromo": @"isPromo",
@"IsNew": @"isNew",
}];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:rubriekMapping
pathPattern:nil
keyPath:@"ds-ttitems.tt-items" statusCodes:[NSIndexSet indexSetWithIndex:200]];
NSArray *arrResponsDescriptor = [[NSArray alloc]initWithObjects:responseDescriptor, nil];
[objectManager addResponseDescriptorsFromArray:arrResponsDescriptor];
return objectManager;
}
还有一个dataModel类,在这个类中我设置了我的对象库。 这一切都很顺利,一切都正确设置。 现在我的要求就是这样做的。
-(void)fetchRubrieken{
API *api = [API new];
RKManagedObjectStore *store = [[ClaesDataModel sharedDataModel] objectStore];
NSManagedObjectContext *context = store.mainQueueManagedObjectContext;
RKObjectManager *objectManager = [api mapGetItems];
NSString *request = @"/claes/items.json";
[objectManager getObjectsAtPath:request parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSError *error = nil;
BOOL success = [store.mainQueueManagedObjectContext save:&error];
if (!success) RKLogWarning(@"Failed saving managed object context: %@", error);
NSLog(@"done fetching");
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
NSLog(@"Hit error: %@", error);
}];
NSError *error = nil;
[context save:&error];
}
问题不在于它不起作用。这只需要很长时间。所以我的问题是,我怎样才能让它变得更快?
希望有人能帮助我!
亲切的问候,
PS。如果您需要更多细节,我会提供,但我认为这是必不可少的部分。