在Swift 4.0中找到领域的schemaVersion [英] Find schemaVersion of realm in swift 4.0

查看:78
本文介绍了在Swift 4.0中找到领域的schemaVersion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个领域还比较陌生,对于如何获取领域的当前schemaVersion,我确实停留在这里.

I am relatively new in this field, and really stuck here as how to get the current schemaVersion of realm.

我尝试了下面的代码来检查我的schemaVersion

I tried Below code to check my schemaVersion

let configCheck = Realm.Configuration();
    let configCheck2 = Realm.Configuration.defaultConfiguration;
    let schemaVersion = configCheck.schemaVersion
    print("Schema version \(schemaVersion) and configCheck2 \(configCheck2.schemaVersion)")

但是输出始终为零

Schema version 0 and configCheck2 0

但是当我迁移时,我已经通过This

But I have already changed my schemaVersion when Migrated, by This

        let config = Realm.Configuration(
        schemaVersion: 2,
        migrationBlock: { migration, oldSchemaVersion in

            if (oldSchemaVersion < 2) {
                // Nothing to do!

            }
    })
    Realm.Configuration.defaultConfiguration = config

我找到了这个答案

schemaVersionAtPath(_:encryptionKey:error:).

我不了解这些参数. 任何带有参数的示例都会非常有帮助.

I am not understanding the parameters. Any example with prameters would be really helpful.

推荐答案

我正在回答自己的问题

let configCheck = Realm.Configuration();
    do {
         let fileUrlIs = try schemaVersionAtURL(configCheck.fileURL!)
        print("schema version \(fileUrlIs)")
    } catch  {
        print(error)
    }

输出为

schema version 2

这篇关于在Swift 4.0中找到领域的schemaVersion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆