Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ios

realm

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?

like image 811
SaintTail Avatar asked Apr 22 '16 05:04

SaintTail


Video Answer


2 Answers

I found this answer here

let configCheck = Realm.Configuration();
do {
     let fileUrlIs = try schemaVersionAtURL(configCheck.fileURL!)
    print("schema version \(fileUrlIs)")
} catch  {
    print(error)
}
like image 161
Azim Talukdar Avatar answered Sep 28 '22 06:09

Azim Talukdar


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:).

like image 40
marius Avatar answered Sep 28 '22 05:09

marius