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