Friday, 15 February 2013

ios - the entity Shop is not key value coding-compliant for the key "category.name" -



ios - the entity Shop is not key value coding-compliant for the key "category.name" -

i'm developing ios application coredata.

i have these 2 entities:

shop

category

i'm trying access category.name shop entity error:

- (void)updatedetails:(nsmanagedobject *)shop { nslog(@"updatedetails: %@", shop); if (shop == nil) return; self.namelabel.text = [[shop valueforkey:@"name"] description]; self.categorylabel.text = [[shop valueforkey:@"category.name"] description]; self.addresslabel.text = [[shop valueforkey:@"address"] description]; self.telephonelabel.text = [[shop valueforkey:@"telephone"] description]; nsnumberformatter* f = [[nsnumberformatter alloc] init]; [f setnumberstyle:nsnumberformatterdecimalstyle]; nsnumber* acceptrate = [f numberfromstring:[[shop valueforkey:@"acceptrate"] description]]; _ratingcontrol.rating = [acceptrate unsignedintvalue]; }

i retrieve shop entities way:

nsmanagedobjectcontext *context = [self managedobjectcontext]; nsentitydescription *entity = [nsentitydescription entityforname:@"shop" inmanagedobjectcontext:context]; nsfetchrequest *fetchrequest = [[nsfetchrequest alloc] init]; [fetchrequest setentity:entity]; nsarray *results = [context executefetchrequest:fetchrequest error:nil];

but error:

'[<nsmanagedobject 0x1cdb4890> valueforundefinedkey:]: entity shop not key value coding-compliant key "category.name".'

how can solve error?

self.categorylabel.text = [[shop valueforkey:@"category.name"] description];

should be

self.categorylabel.text = [[shop valueforkeypath:@"category.name"] description];

reason: key value coding documentation

a key string identifies specific property of object. typically, key corresponds name of accessor method or instance variable in receiving object. keys must utilize ascii encoding, begin lowercase letter, , may not contain whitespace.

some illustration keys payee, openingbalance, transactions , amount.

a key path string of dot separated keys used specify sequence of object properties traverse. property of first key in sequence relative receiver, , each subsequent key evaluated relative value of previous property.

for example, key path address.street value of address property receiving object, , determine street property relative address object.

ios core-data

No comments:

Post a Comment