如何使用MagicalRecord设置Core Data轻量级迁移? [英] How do I set up Core Data lightweight migration using MagicalRecord?
问题描述
我打了一个砖墙,试图使用MagicalRecord设置轻量级的Core Data迁移。我已经查看了关于这个问题的所有帖子,使用Google和SO。我了解 persistentStoreCoordinator 的工作方式以及我想要进行的设置。
I have hit a brick wall trying to setup lightweight migration of Core Data using MagicalRecord. I have looked at all of the posts on this subject, using Google and SO. I understand how the persistentStoreCoordinator works and what the settings I am trying to make also do.
这是我的代码:
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;
}
以下错误,我明白;我不知道这些对象在哪里(我已经在我的应用程序,看不到任何东西):
I'm getting the following errors, which I understand; what I don't know is where are these objects (I have looked in my app, and found nothing):
没有可见@interface 'AppDelegate'声明选择器'applicationDocumentsDirectory'和
No visible @interface for 'AppDelegate' declares the selector 'applicationDocumentsDirectory' and
没有可见@interface for'AppDelegate'声明选择器'managedObjectModel'
No visible @interface for 'AppDelegate' declares the selector 'managedObjectModel'
我已经创建了商店:
大多数,如果不是所有的代码我看过是类似的;我不知道MagicalRecord是否为我处理这个,因为我找不到任何文档,指示如何使用MR。我的问题是:我需要做什么来使这项工作?
Most, if not all of the code I have looked at is similar; I don't know if MagicalRecord handles this for me or not because I can't find any docs that would indicate how to do this using MR. My question is: what do I have to do to make this work?
推荐答案
MagicalRecord的要点是, for:
The whole point of MagicalRecord is that this is managed for you:
[MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:####];
检查有关Core Data堆栈设置的文档这里。
Check the docs about the Core Data stack setup here.
这篇关于如何使用MagicalRecord设置Core Data轻量级迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!