ronatory ronatory - 2 months ago 75
Swift Question

Can't open Swift realm databases with Browser, need to update even using the latest RealmSwift version

I'm doing this tutorial and there they use

pod 'RealmSwift', '~> 0.98'
. But when I try to open the
default.realm
file with the Realm Browser
Version 2.0.0 (78)
. There is always the alert

'default.realm' is at an older file format version and must be upgraded before it can be opened. Would you like to proceed?


enter image description here

So I tried to use the latest version of RealmSwift. Even with using the latest version, the message appears.

When I proceed and upgrade the file, I can open it and see also the records. But the problem is, when I close the realm browser after this and start the app again, an error appears

fatal error: 'try!' expression unexpectedly raised an error: ... "Unable to open a realm at path ... Unsupported Realm file format version."


Note: As in the tutorial mentioned, they use try! instead of try and do/catch for simplifying

So how can I open the realm file with or without upgrading it and still have an working app after accessing the file again with app?

Searched for other solutions on SO, but didn't find one so far.

Answer

It looks like your essentially getting a mismatch between your cocoapods version of Realm and the version RealmBrowser is expecting. I think you have 2 options:

1) Upgrade RealmSwift cocoapods to match what RealmBrowser is expecting 2) Downgrade RealmBrowser version to match what version of RealmSwift cocoapods you have

The issue you're seeing of fatal error: 'try!' expression unexpectedly raised an error: ... "Unable to open a realm at path ... Unsupported Realm file format version." is because the RealmBrowser application is upgrading your realm database file, and then when you go back to the application, it is now in a "too-upgraded" format, so to speak.