ios - Saving in Core Data -
at abcviewcontroller.m
product *pro = [nsentitydescriptioninsertnewobjectforentityforname:@"product" inmanagedobjectcontext:_appdelegate.managedobjectcontext]; pro.name = _nametext.text; [_context insertobject:pro]; [_appdelegate savecontext];
savecontext in appdelegate contains
- (void)savecontext { nsmanagedobjectcontext *managedobjectcontext = self.managedobjectcontext; if (managedobjectcontext != nil) { nserror *error = nil; if ([managedobjectcontext haschanges] && ![managedobjectcontext save:&error]) { // replace implementation code handle error appropriately. // abort() causes application generate crash log , terminate. should not use function in shipping application, although may useful during development. nslog(@"unresolved error %@, %@", error, [error userinfo]); abort(); } } }
any need of "[_context insertobject:pro];" @ abcviewcontroller.m saving coredata file context????
unless _appdelegate.managedobjectcontext
, _context
2 different nsmanagedobjectcontext
's, don't need explicitly call insertobject
inserted new product
object nsentitydescriptioninsertnewobjectforentityforname
Comments
Post a Comment