1
我想创建一个由不同类类型组成的通用领域列表(但是所有超类Object
)。从领域中的通用列表获取反向关系
class Parent: Object {
var children = List<Object>()
}
class Child1: Object {
let parents = LinkingObjects(fromType: Parent.self, property: "children")
}
class Child2: Object {
let parents = LinkingObjects(fromType: Parent.self, property: "children")
}
联Child1
和Child2
实例为Parent
对象工作正常,但是,逆关系提供了以下错误:
- Property ‘Parent.children’ declared as origin of linking objects property ‘Child1.parents’ links to a different class.
- Target type 'RealmSwiftObject' doesn't exist for property ‘children’.
怎么可能在parents
属性正确地确定它保证?我可以想象它应该根据它所属的类别类型进行过滤(即Child1
或Child2
),但我不知道该怎么做?
这是正确的。 Realm通常不支持类型多态。有关详细信息和解决方法,请参阅https://realm.io/docs/swift/latest/#model-inheritance。 – jpsim
我在文档中忽略了这一点,但我会尽力找到解决方法。 – Taco