objective c - NSManagedObjectContext: autoupdate or not? -


i need understand nsmanagedobjectcontext update. have uisplitview uitableviewcontroller on rootview , uiviewcontroller on detail view. when tap in row data, load data labels , uitextview can update field:

- (void)textviewdidendediting:(uitextview *)textview { nsindexpath *indexpath = [self.tableview indexpathforselectedrow]; [[listofadventures objectatindex:indexpath.row] setadventuredescription:textview.text]; } 

ok. works correctly, description updated. also, might wants delete row:

- (void)tableview:(uitableview *)tableview commiteditingstyle:(uitableviewcelleditingstyle)editingstyle forrowatindexpath:(nsindexpath *)indexpath {  if (editingstyle == uitableviewcelleditingstyledelete) {     nspredicate *predicate = [nspredicate predicatewithformat:@"playerplaysadventure.adventurename==%@",[[listofadventures objectatindex:indexpath.row] adventurename]];     nsarray *results = [[adventurefetcher sharedinstance] fetchmanagedobjectsforentity:@"player" withpredicate:predicate withdescriptor:@"playername"];      [moc deleteobject:[listofadventures objectatindex:indexpath.row]];     ( player *player in results ) {         [moc deleteobject:player];     }     [listofadventures removeobjectatindex:indexpath.row];     [tableview deleterowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:yes];     [self cleardetailviewcontent];     nserror *error = nil;     if ( ![moc save:&error] ) {         nslog( @"errore nella cancellazione del contesto!" );         abort();     } }    else if (editingstyle == uitableviewcelleditingstyleinsert) {     // create new instance of appropriate class, insert array, , add new row table view }    } 

so here's problem: if comment rows saving of moc, adventure momentarily deleted. if quit app , reopen it, object still there. doesn't happen update of field. i'd know why , if should save moc in textviewdidfinishediting method. thank in advance.

it's difference between changing attribute of object , adding or removing entire object in object graph.

in first block, change attribute of existing object saves automatically unless run undo. because object exist in object graph , no other objects have altered make change.

in second block, removing entire object , potentially altering object graph changing relationships between objects. change not committed until implicit save because potentially can trigger cascade of changes throughout large number of objects.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -