如何使用Magical Record设置自动迁移核心数据堆栈?

时间:2016-02-16 12:25:00

标签: ios swift core-data

这就是我目前设置核心数据堆栈的方式:

func setupCoreDataStack() {

    if NSPersistentStoreCoordinator.MR_defaultStoreCoordinator() != nil {
        return
    }

    let managedObjectModel = NSManagedObjectModel.MR_defaultManagedObjectModel()
    let persistentStoreCoordinator = NSPersistentStoreCoordinator(managedObjectModel: managedObjectModel!)
    var storePath = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier(PBOSharedGroupName)
    storePath = storePath!.URLByAppendingPathComponent("POSowner.sqlite")

    try! persistentStoreCoordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: storePath, options: nil)
    NSPersistentStoreCoordinator.MR_setDefaultStoreCoordinator(persistentStoreCoordinator)
    NSManagedObjectContext.MR_initializeDefaultContextWithCoordinator(persistentStoreCoordinator)
}

但我不知道如何更改设置自动迁移核心数据堆栈。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

添加以下选项:

let options = [NSMigratePersistentStoresAutomaticallyOption: true, NSInferMappingModelAutomaticallyOption: true]

作为addPersistentStoreWithType:

的参数