Model Inheritence Does Not Match RLMArray type

Given the following three models:

class SourceOperator: SyncOperator { ... }

class RestSourceOperator: SourceOperator { ... }

class BatchOperator: AggregateOperator { let sources = List<SourceOperator>() ... }

After instantiating a RestSourceOperator which inherits from SourceOperator and attempt to append it to the BatchOperator instance the application crashes with:

Terminating app due to uncaught exception ‘RLMException’, reason: 'Object of type ‘RestSourceOperator’ does not match RLMArray type ‘SourceOperator’.'

I’d like to avoid hacking around our domain model, any suggestions around handling this exception and helping persist a RestSourceOperator while still extending the base class?

Realm doesn’t support inheritance, so you can’t add a child class to a collection of the base one.

I hope we can add this to the roadmap.
I found the following thread useful Abstract Class / Polymorphism Support · Issue #1109 · realm/realm-swift · GitHub

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.