How can I check my realm schema version without opening the realm file?

牧云@^-^@ 提交于 2020-01-02 04:54:12

问题


The problem we face is we cannot migrate with the new schema version so we want to wipe out all the realm data clean and create a new one instead (for all the user who have schema version less than this new number).

But I cannot find a way for me to know this number except only during in the migration block.

Is there a way to know this schema version else where?


回答1:


Technically you can't check the schema version without accessing the Realm file at all, but you don't need full access and specify a matching schema to read just the schema version. We have functions to allow exactly that.

From Objective-C, you can use the class method:
+[RLMRealm schemaVersionAtPath:error:]

From Realm Swift, you can use the free function: schemaVersionAtPath(_:encryptionKey:error:).




回答2:


I found this answer here

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


来源:https://stackoverflow.com/questions/36785743/how-can-i-check-my-realm-schema-version-without-opening-the-realm-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!