RealmList question


(Darrin Smith) #1

Let’s say I have the following RealmObject (in Kotlin)

open class SomeHistory:RealmObject() {
    @PrimaryKey
    var timeStampOfStart = 0L
    var someUUID = ""
    var floatList1 = RealmList<Float>(0.0f)
    var floatList2 = RealmList<Float>(0.0f)
    var intList1 = RealmList<Int>(0)
}

Now, the floatList1, floatList2, and floatList1 lists are tied together such that floatList1[0] is tied to floatList2[0] and intList1[0]. In other words, you want the same index used to get the data from each.

Instead of having three separate fields like this, it would be cleaner to use 1 that ties them all together. So the above would go to this:

open class SomeHistory:RealmObject() {
    @PrimaryKey
    var timeStampOfStart = 0L
    var someUUID = ""
    var tiedData = RealmList<TiedData>()
}

Then you would need to define a class for TiedData which looks something like this:

open class TiedData:RealmObject() {
    var floatItem1 = 0.0f
    var floatItem =0.0f
    var intItem1 = 0
}

My questions are, does TiedData even need to extend RealmObject and if so, do you have to store (commit to storage) the TiedData objects themselves or will Realm do that if you simply create the SomeHistory object and save that given it includes TiedData (which you would populate)?

Thanks.