ios – 如何使用MagicalRecord设置Core Data轻量级迁移?

我试图使用MagicalRecord设置Core Data的轻量级迁移.我使用Google和SO查看了有关此主题的所有帖子.我理解persistentStoreCoordinator如何工作以及我想要做的设置也是如此.

这是我的代码:

AppDeligate.h

NSPersistentStoreCoordinator *persistentStoreCoordinator;

AppDelegate.m

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {

if (persistentStoreCoordinator != nil) {
    return persistentStoreCoordinator;
}

NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"saori.sqlite"]];

// handle db upgrade
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                         [NSNumber numberWithBool:YES],NSMigratePersistentStoresAutomaticallyOption,[NSNumber numberWithBool:YES],NSInferMappingModelAutomaticallyOption,nil];

NSError *error = nil;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];

if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {

    // Handle error
}

return persistentStoreCoordinator;

}

我得到以下错误,我理解;我不知道的是这些对象在哪里(我在我的应用程序中查找,并没有找到任何内容):

No visible @interface for ‘AppDelegate’ declares the selector ‘applicationDocumentsDirectory’ and

No visible @interface for ‘AppDelegate’ declares the selector ‘managedObjectModel’

我已经创建了商店:

大多数,如果不是所有我看过的代码都是相似的;我不知道MagicalRecord是否会为我处理这个问题,因为我找不到任何可以指示如何使用MR执行此操作的文档.我的问题是:我需要做些什么来完成这项工作?

解决方法

MagicalRecord的重点在于为您管理:
[MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:####];

查看有关Core Data堆栈设置here的文档.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...