我现在正在使用 restkit 一段时间。一切都很完美。但现在我想将一个 json 映射到我的核心数据库中。这是一个 (10 MB) 的 JSON。你可以在这里看到 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。如果您需要更多详细信息,我会提供,但我认为这是必不可少的部分。