gpt4 book ai didi

swift - 在 MacOS 应用程序中设置 Realm 架构版本

转载 作者:行者123 更新时间:2023-11-28 10:53:25 28 4
gpt4 key购买 nike

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

Main.c(或 main.swift)似乎已经退休并且没有过多更改 AppDelegate,我唯一能想到调用 schemaVersion 的地方是在初始 View Controller 的 ViewDidLoad 中,这对我来说看起来很丑。

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

最佳答案

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
}
...
}

关于swift - 在 MacOS 应用程序中设置 Realm 架构版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45002257/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com