我的对象
class RealmConversation: Object {
@objc dynamic var id = ""
var show = List<Show_id>()
var show_ids: [String] {
get {
return show.map { $0.show_id }
}
set {
show.removeAll()
show.append(objectsIn: newValue.map {Show_id(value: [$0])})
}
}
override class func ignoredProperties() -> [String] {
return ["show_ids"]
}
override static func primaryKey() -> String? {
return "id"
}
}
class Show_id:Object {
@objc dynamic var show_id = ""
}
附加 View Controller
newSpecimen.show_ids = ["id1", "id2", "id3"]
realm.add(newSpecimen, update: true)
self.realmconversation = newSpecimen
最佳答案
If you don’t want to save a field in your model to its Realm, override Object.ignoredProperties(). Realm won’t interfere with the regular operation of these properties; they’ll be backed by ivars, and you can freely override their setters and getters. Realm documentation
为此,在添加新对象之前,您应该检查 show_ids 是否包含您要添加的 id。
关于swift - Realm swift update List 写入每个运行时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48088865/