ios - Why isn't core data maintaining persistance in this code? -
this code
+(favouritesmodel *) savefavourites: (nsstring *) title and: (nsstring *) subtitle{ favouritesmodel *savedata = [[favouritesmodel alloc] init]; savedata.context = [savedata managedobjectcontext]; nsmanagedobject *task = [[favourites alloc] initwithcontext:savedata.context]; [task setvalue:title forkey:@"title"]; [task setvalue:subtitle forkey:@"subtitle"]; nsstring *titlestr = [task valueforkey:@"title"]; nsstring *subtitlestr = [task valueforkey:@"subtitle"]; [savedata.favouritesdata addobject:titlestr]; [savedata.favouritesdata addobject:subtitlestr]; appdelegate *appdelegate; [appdelegate savecontext]; return savedata; }
the data want saved it's not persisting. i've used savecontext() method in "applicationwillterminate" in app delegate too. still if i'm quitting , reopening app, data not there.
edit i'm using model class call method in 5 classes.
what have add implement data persistence ?
put breakpoint on second of these lines
appdelegate *appdelegate; [appdelegate savecontext]; // <----- here
appdelegate not being set correctly , breakpoint confirm this.
it needs set [something] this:
// untested appdelegate = (appdelegate*)[[uiapplication sharedapplication] delegate];
Comments
Post a Comment