【发布时间】:2015-10-14 00:10:01
【问题描述】:
我刚从领域开始,我认为我已经正确创建了两个对象。一个 ColourCategory 可以有许多 PaletteColour 类型的对象
class PaletteColour: Object {
dynamic var name = ""
dynamic var category: ColorCategory?
}
class ColourCategory: Object {
dynamic var name = ""
let paletteColours = List<PaletteColour>()
}
我已经创建了许多类别,只是通过使用名称来创建它们。 现在,我想添加颜色,并且 PaletteColour 的属性之一是它必须具有按名称指向类别对象的链接。
我被困在如何使用我的类别名称之一创建 PaletteColour 对象。
我从这个开始
let realm = try! Realm()
newColour = PaletteColour()
newColour.name = "Red"
// This is where I am stuck
// How do I add a category property that has a name of "Test Category" and linked to the ColourCategory object
newColour.category = ????????????
realm.write {
realm.add(newColour)
}
我确信这很简单,因此我们将不胜感激。
【问题讨论】:
标签: realm