Search code examples
iosiphoneswiftrealmrlmarray

RLMArray object not stored with its object


I've a very weird problem in RealmSwift. I've the following property in a realm object class called Device.

class Device: Object {
    ....
    dynamic var name: String = ""
    var services: List<Service> = List<Service>()
}

The issue is that when trying to fill this list and save the Device object, the service list is not saved.

While debugging I used the following to test

print(device)

Which prints the objects without any service object. and

print(device.services)

Which prints all services objects. I know it's weird, but I cannot save the object with its list object, although I can save any normal property in the device object like name property. Any idea what is happening here?


Solution

  • What you are describing could happen if you are directly assigning to the services property. This is not supported, and List properties should always be declared as let.