ios - Can't make Restkit 0.20 + CoreData work -
i trying fetch content http json resource (categories list) , connect restkit , coredata.
my mapping used work when didnt utilize coredata. decided utilize next tutorial:
http://www.alexedge.co.uk/portfolio/introduction-restkit-0-20/
however, getting weird error , cant find out why:
the entity (null) not key value coding-compliant key "remoteid"
my category model / entity has remoteid mapped id on server, not issue. however, error seems restkit or coredata cant figure out entity i'm talking (they null entity??)
this 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); } homecoming _fetchedresultscontroller; }
and 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])
work. did seek next code?
nsfetchrequest *fetchrequest = [nsfetchrequest fetchrequestwithentityname:@"category"];
additionally check out illustration core info project within of restkit v.020-rc1 zip file see how things going.
ios json core-data restkit
No comments:
Post a Comment