androidiosxamarinrealmrealm-migration

Is Realm database portable


Is a realm database portable across development frameworks/languages.

If i wrote version 1 of an Android or iOS app in Xamarin with a Realm database, then for version 2 of the app I rewrote it natively.

Would I have any problems when upgrading the Realm database when upgrading the app from version 1 to version 2.

If so how would I handle any issues?


Solution

  • The short answer is Yes, Realm DBs are portable.

    You can see this in action by using the Realm Studio as this app runs on Linux, MacOS, Windows and has an option to open a sample database that is downloaded from Realm and opens in any OS correctly, you could copy this DB to an Android|iOS device and use it within your Realm code without change.

    Now, of course, your model's implementation is language dependent, and would have to be changed if you change the language of your Realm-based application.

    Same RealmTestClass2 model across different languages:

    C# model:

    public class RealmTestClass2 : RealmObject
    {
        [MapTo("integerValue")]
        public long IntegerValue { get; set; }
    
        [MapTo("boolValue")]
        public bool BoolValue { get; set; }
    
        [MapTo("objectReference")]
        public RealmTestClass1 ObjectReference { get; set; }
    }
    

    Swift Model:

    class RealmTestClass2: Object {
        @objc dynamic var integerValue: Int = 0
        @objc dynamic var boolValue: Bool = false
        @objc dynamic var objectReference: RealmTestClass1?
    }
    

    Kotin Model:

    open class RealmTestClass2 : RealmObject() {
        var integerValue: Long = 0
        var boolValue: Boolean = false
        var objectReference: RealmTestClass1? = null
    }