【发布时间】:2014-08-04 21:48:12
【问题描述】:
我在我的 iOS 应用程序中使用 MR。我使用它的方式与以前的应用程序相同,但我的对象没有保存在数据库中。
我从调试中看到 Magical Record 在setupAutoMigratingCoreDataStack 方法中正确找到了*.sqlite 数据库
这里是一些示例测试代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[MagicalRecord setupAutoMigratingCoreDataStack];
NSManagedObjectContext *sampleContext = [NSManagedObjectContext MR_defaultContext];
NSLog(@"hasChanges: %d", [sampleContext hasChanges]);
self.entity = [MyEntity MR_createEntityInContext:sampleContext];
NSLog(@"hasChanges: %d", [sampleContext hasChanges]);
[sampleContext MR_saveOnlySelfWithCompletion:^(BOOL success, NSError *error) {
NSLog(@"save: %d %@", success, error);
}];
return YES;
}
这是输出:
hasChanges: 0
hasChanges: 1
save: 1 (null)
我重新打开应用程序,发现本地数据库 ([MyEntity MR_findAll]) 中没有保存任何实体,我还打开 *.sqlite 数据库,发现 ZMyEntity 表为空。
这种行为的原因是什么?
提前致谢!
【问题讨论】:
标签: ios sqlite core-data magicalrecord