问题
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