[英]Can't make Restkit 0.20 + CoreData work
I am trying to fetch content from a http json resource (categories list) and connect it with restkit and coredata. 我正在尝试从http json资源(类别列表)中获取内容,并将其与restkit和coredata连接起来。
My mapping used to work when I didnt use CoreData. 当我不使用CoreData时,我的映射就可以正常工作了。 Then I decided to use the following tutorial: 然后,我决定使用以下教程:
http://www.alexedge.co.uk/portfolio/introduction-restkit-0-20/ http://www.alexedge.co.uk/portfolio/introduction-restkit-0-20/
However, I am getting a weird error and I just cant find out why: 但是,我收到一个奇怪的错误,而我却找不到原因:
the entity (null) is not key value coding-compliant for the key "remoteId"
My category model / entity has the remoteId mapped to id on my server, so that is not the issue. 我的类别模型/实体将remoteId映射到我的服务器上的id,所以这不是问题。 However, from the error it seems that Restkit or CoreData cant figure out which entity I'm talking about (they say it is a null entity??) 但是,从该错误看来,Restkit或CoreData似乎无法弄清我正在谈论的实体(他们说这是一个空实体?)
This is the request code: 这是请求代码:
- (NSFetchedResultsController *)fetchedResultsController{
if (!_fetchedResultsController) {
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:NSStringFromClass([Category class])];
fetchRequest.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES]];
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:[RKManagedObjectStore defaultStore].mainQueueManagedObjectContext sectionNameKeyPath:nil cacheName:@"Category"];
self.fetchedResultsController.delegate = self;
NSError *error;
[self.fetchedResultsController performFetch:&error];
NSLog(@"%@",[self.fetchedResultsController fetchedObjects]);
NSAssert(!error, @"Error performing fetch request: %@", error);
}
return _fetchedResultsController;
}
And the mapping: 和映射:
+(void) prepareMapping {
RKObjectManager *manager = [RKObjectManager sharedManager];
NSDictionary *categoryAttributes = @{
@"id" : @"remoteId",
@"created_at" : @"updatedAt",
@"created_at" : @"createdAt",
@"name" : @"name",
@"ads_count": @"adsCount",
};
RKEntityMapping *categoryMapping = [RKEntityMapping mappingForEntityForName:@"Category" inManagedObjectStore:manager.managedObjectStore];
[categoryMapping addAttributeMappingsFromDictionary:categoryAttributes];
categoryMapping.identificationAttributes = @[@"remoteId"];
[manager addResponseDescriptorsFromArray:@[
[RKResponseDescriptor responseDescriptorWithMapping:categoryMapping
pathPattern:@"neighborhoods/:neighborhoodId/categories.json"
keyPath:@"index_categories.index_category"
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]
]];
}
I don't know if NSStringFromClass([Category class])
will work. 我不知道NSStringFromClass([Category class])
是否会工作。 Did you try the following code? 您是否尝试了以下代码?
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Category"];
Additionally you could check out the example core data project inside of the RestKit v.020-rc1 zip file to see how things are going. 另外,您可以在RestKit v.020-rc1 zip文件中查看示例核心数据项目,以了解进展情况。
我认为您提到的博客现在已经移至: http : //www.alexedge.co.uk/blog/2013/03/08/introduction-restkit-0-20/
http://nsscreencast.com/episodes/52-restkit-coredata http://nsscreencast.com/episodes/52-restkit-coredata
Goes in depth of the integration 深入整合
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.