ios - How to get values for object in didChangeObject:(id)anObject (NSfetchedResultsController) -
how can access object actual values in fetchedresultscontroller delegate method ?
i want set section of indexpath rows delete/change according values of object, table has multiple datasources
- (void)controller:(nsfetchedresultscontroller *)controller didchangeobject:(id)anobject atindexpath:(nsindexpath *)indexpath forchangetype:(nsfetchedresultschangetype)type newindexpath:(nsindexpath *)newindexpath { ....get objects value, e.g. myentity.city } now know object of class myentity (at least ultimately, not sure "anobject" refers to), compiler complains when want set instance of myentity *anentity = anobject;
my workaround has been put data each section arrays, , work in tableview:commiteditingstyle:forrowatindexpath: know section called , need access indexpath.row. drawback have reload arrays after each change , can not directly work fetchedresultscontroller.
edit: accepted answer works fine, shortcut seems work purpose:
nsstring *astring = [anobject valueforkey:@"city"];
the compiler complain, it's warning because haven't told expect. it's simple as:
myentity *anentity = (myentity *)anobject; that said, need sure it's correct class, pays add little protection:
if ([anobject iskindofclass:[myentity class]) { myentity *anentity = (myentity *)anobject; // stuff } else { nslog(@"panic / cry / plead"); }
Comments
Post a Comment