iphone - Trouble saving Core Data objects via iOS -
i saving core data objects until now. in code, i'm searching objects , want update or add property saved object.
apparently won't save changes, idea why?
nsmanagedobjectcontext *managedobjectcontext = ((ventoappdelegate*) [[uiapplication sharedapplication] delegate]).managedobjectcontext; nsentitydescription *entitydescription = [nsentitydescription entityforname:entitynamestring inmanagedobjectcontext:managedobjectcontext]; nsfetchrequest *request = [[[nsfetchrequest alloc] init] autorelease]; [request setentity:entitydescription]; nserror *error; nsarray *objects = [managedobjectcontext executefetchrequest:request error:&error]; if (objects == nil) { nslog(@"error - events=nil - %@", [error localizeddescription]); } if ([objects count] > 0) { (nsmanagedobject* object in objects) { if (distance <= maxdistance) { if (bla-bla-bla) { [object setvalue:[nsnumber numberwithbool:yes] forkey:@"notification"]; [self savecontext]; } } } } thank you!
if change managed object changed in memory. need save managed context after changing anything. add this:
nserror *error; if (![object.managedobjectcontext save:&error]) { // update handle error appropriately. nslog(@"unresolved error %@, %@", error, [error userinfo]); abort(); // fail }
Comments
Post a Comment