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

标签 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)
}

但我不知道要更改什么来设置自动迁移核心数据堆栈。

感谢您的帮助。

最佳答案

添加以下选项:

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

作为addPersistentStoreWithType:的参数

关于ios - 如何使用 Magical Record 设置自动迁移核心数据堆栈?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35432561/

相关文章:

ios - 如何使用 Swift 从 iOS 访问/流式传输 IP 摄像机(RTSP、ONVIF)

iphone - 关闭 MPMoviePlayerViewController 的全屏模式时出现问题

iphone - 在 iPhone 中检测图片的图像位置

ios - 无法加载测试包,因为出现意外错误

ios - 在多个 View Controller 中使用 FetchedResultsController 和 ManagedObjectContext

core-data - 查询/过滤具有共同父级且不符合键值的核心数据实体

iphone - 使用核心数据在 View 中引用模型对象的最佳实践是什么?

ios - 使用 RxSwift 和 RXCocoa 在按钮单击时验证所有文本字段

ios - AND 和 OR 与 NSPredicate 结合。 iOS swift

swift - 如何在 xcode 的 Playground 中导入 RxSwift?