开发者

Core Data Saving to Database not Working

开发者 https://www.devze.com 2023-01-20 02:00 出处:网络
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.

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 < [m开发者_JAVA技巧utableFetchResults 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 was expecting to see a line where you delete the object from the managedObjectContext:

[manageObjectContext deleteObject:toDelete];

assuming manageObjectContext is your context, and toDelete is a managedObject in your context, or mutableFetchResults.

Then I expected to see the save directly afterwards.

0

精彩评论

暂无评论...
验证码 换一张
取 消