从领域中的通用列表中获取反向关系

时间:2016-08-25 08:57:04

标签: ios realm

我想创建一个由不同类类型组成的通用领域列表(但是所有超类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")
}

Child1Child2的实例链接到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属性?我可以想象它应该被过滤掉它所属的类类型(即Child1Child2),但我不知道该怎么做?

1 个答案:

答案 0 :(得分:0)

除非有我不知道的解决方法,否则无法在List中存储不同的类型。

List包含单个类型的其他Object,其界面与可变Array非常相似。 (https://realm.io/docs/swift/latest/#to-many-relationships

相关问题