核心数据 - 对持久性存储的更新无效

时间:2012-03-04 13:40:57

标签: iphone core-data

这让我疯狂地试图解决这个问题......

我有一个托管对象,我需要设置一个属性来标记记录是最喜欢的

问题是我没有看到保存到数据库的值(我已经从模拟器中取出数据库并检查了它?)

以下是代码片段...请注意,保存

不会引发任何错误
// Tell the user we have added to favorites

NSString *yes = @"Y";

[cardMessage setValue:yes forKey:@"favorite"];

NSError *error = nil;
BOOL savedSuccessfully = [managedObjectContext save:&error];
if (!savedSuccessfully)
{
     /*
     Replace this implementation with code to handle the error appropriately.

     abort() causes the application to generate a crash log and terminate. 
         You should not use this function in a shipping application, although it 
         may be useful during development. 
     */
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    abort();
}

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil 
       message:@"Message added to Favorites" delegate:self 
       cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];

1 个答案:

答案 0 :(得分:0)

您可以使用SQLite Manager(浏览器插件)从Simulator db中查看数据 - 快速简便(Firefox插件)。 https://code.google.com/p/sqlite-manager/ 使用 - (BOOL)hasChanges - 万一意外出错(例如没有变化)。