您必须保存它们才能成为持久性 - 见 苹果核心数据编程指南中"控制对象背景 :
但是,除非你真的保存这些变化, 持久存储仍然未变。
所以这里就是代码
NSError *error = nil;
BOOL savedSuccessfully = [self.managedObjectContext save:&error];
if (!savedSuccessfully) {
NSLog(@"Could not save date change! Reason : %@", [error localizedDescription]);
}
您应该经常保存, 而不是在退出应用程序时保存 。 见这个答案 : < a href="https:// stackoverflow.com/q/ 3085170/1059709" 。 a >
当我改变产品、删除产品或添加产品时,
这取决于您在核心数据模型的实体中设定的删除规则 。
- nullify: any other object in the relationshipto the deleted object will have those relationship set to nil. for to-many relationships the delted object will just be removed from the collection.
- cascade: any other object with a relationship to the object is deleted too.
- deny: the delete will ne denied if there are any other related objects.
- no action: any other object with a relation to the object will be left unchanged.