核心数据保存到数据库不起作用
我是 iPhone 的第一次 Core Data 用户/学习者,我认为 [managementObjectContext save:$error]
用于保存对持久存储的更改。
但是当我重新加载并调用 NSFetch 时,对象仍然存在。有什么想法吗?
for (int i ; i < [mutableFetchResults count];i++)
{
NSManagedObject *toDelete = [mutableFetchResults objectAtIndex:i];
[managedObjectContext toDelete];
// Update the array and table view.
[mutableFetchResults removeObjectAtIndex:i];
}
if (![managedObjectContext save:&error]) {
// Handle the error.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
exit(-1); // Fail
}
I'm a first time Core Data user/learner for iPhone, I thought that [managedObjectContext save:$error]
was used to save changes to the Persistant Store.
But when I reload and call NSFetch, the objects are still there. Any ideas why?
for (int i ; i < [mutableFetchResults count];i++)
{
NSManagedObject *toDelete = [mutableFetchResults objectAtIndex:i];
[managedObjectContext toDelete];
// Update the array and table view.
[mutableFetchResults removeObjectAtIndex:i];
}
if (![managedObjectContext save:&error]) {
// Handle the error.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
exit(-1); // Fail
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我期望看到一行从 ManagedObjectContext 中删除对象:
假设 manageObjectContext 是您的上下文,而 toDelete 是您上下文中的 ManagedObject 或 mutableFetchResults。
然后我希望之后能直接看到保存。
I was expecting to see a line where you delete the object from the managedObjectContext:
assuming manageObjectContext is your context, and toDelete is a managedObject in your context, or mutableFetchResults.
Then I expected to see the save directly afterwards.