【问题标题】:Setting Realm schema version in MacOS app在 MacOS 应用程序中设置领域架构版本
【发布时间】:2017-07-10 00:19:26
【问题描述】:

与 iOS 不同,应用委托的 applicationWillFinishLaunching 和 applicationDidFinishLaunching 在初始 NSViewController 上的 ViewDidLoad 之后调用

Main.c(或 main.swift)似乎已退役,并且没有过多更改 AppDelegate,我能想到的唯一调用 schemaVersion 的地方是初始视图控制器的 ViewDidLoad,这对我来说似乎很难看。

在用 Swift 编写的 MacOS 应用程序中设置 Realm 的 schemaVersion 的推荐方法是什么?

【问题讨论】:

    标签: swift macos realm


    【解决方案1】:

    MacOS AppDelegate 的 init() 似乎运行良好。

    class AppDelegate: NSObject, NSApplicationDelegate {
    
        override init() {
            super.init()
    
            let info = Bundle.main.infoDictionary!
            let version = info["RealmSchemaVersion"] as! UInt64
            Realm.Configuration.defaultConfiguration.schemaVersion = version
        }
        ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多