现在,要添加一个保存修改的方法。其实很简单,就是调用持久化存储协调器的save方法。
- (void)saveContext { if (debug == 1) { NSLog(@"Running %@ '%@'",self.class, NSStringFromSelector(_cmd)); } if ([_context hasChanges]) { NSError *error; if ([_context save:&error]) { NSLog(@"_context save changes to persistent store."); }else{ NSLog(@"Faild to save changes: %@.",error); } }else{ NSLog(@"SKIPPED _context save ,there are no changes!"); } }