确保在更改后保存上下文。模板方法是:
- (void)saveContext {
NSError *error = nil;
NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
if (managedObjectContext != nil) {
if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) {
// 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.
NKLOG(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
}
如果你想打开你的数据库,你可以试试这个名为SQLite Manager的 firefox 插件
并搜索您的 .sqlite 文件,您的应用程序的默认路径为:
/Users/YOUR_USER/Library/Application Support/iPhone Simulator/IOS_VERSION/Applications/GENERATED_HASH/Documents/YOUR_APP.sqlite