gpt4 book ai didi

ios - RealmSwift - 开始/提交写入

转载 作者:行者123 更新时间:2023-11-28 09:53:58 24 4
gpt4 key购买 nike

在我的健身追踪器应用程序中,我保存当前运行并调用反向地理定位方法,该方法应该获取运行发生的位置名称。

首先我将“latestRun”写入 Realm ,然后等待反向地理编码完成并尝试修改“latestRun”变量

try! realm.write {
realm.add(latestRun)
}

if !savedLocations.isEmpty
{
ReverseGeocoder.getPlace(latitude: savedLocations[0].latitude, longitude: savedLocations[0].longitude, completionHandler: {
place in
realm.beginWrite()
try! realm.write {
latestRun.place = place

}
try! realm.commitWrite()

})
}

结果异常

Terminating app due to uncaught exception 'RLMException', reason: 'The Realm is already in a write transaction'

我做错了什么?我在文档中发现,在这种情况下应使用 beginWrite()commitWrite() 方法。

最佳答案

无需使用 commitWrite()beginWrite()

try! realm.write {
latestRun.place = place
}

足够了

关于ios - RealmSwift - 开始/提交写入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40403044/

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