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

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -