gpt4 book ai didi

ios - 无法更新 Realm 对象

转载 作者:行者123 更新时间:2023-11-28 07:33:35 26 4
gpt4 key购买 nike

我正在使用 swift 更新 Realm 中的对象,但出现错误。

*** Terminating app due to uncaught exception 'RLMException', reason: 'Realm accessed from incorrect thread.'

我的代码:-

let realm = try! Realm()
let cont = Contact()
cont.notes = self.notee
cont.id = self.oneCont.id //i.e id of current object
cont.email = self.email


try! self.realm.write {
self.realm.add(cont,update:true)
}

最佳答案

你有一个本地 Realm

let realm = try! Realm()

但是你正在写一个 class var realm with

try! self.realm.write {

您应该将其更改为使用相同的本地 Realm

let realm = try! Realm()
let cont = Contact()
cont.notes = self.notee
cont.id = self.oneCont.id //i.e id of current object
cont.email = self.email

try! realm.write {
realm.add(cont,update:true)
}

关于ios - 无法更新 Realm 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53912338/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com