【发布时间】:2016-11-03 13:42:31
【问题描述】:
在我的健身追踪器应用程序中,我保存当前跑步并调用反向地理定位方法,该方法应该获取跑步发生的位置名称。
首先我将“latestRun”写入领域,然后等待反向地理编码完成并尝试修改“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()
})
}
结果异常
由于未捕获的异常“RLMException”而终止应用程序,原因:“The Realm 已经处于写入事务中'
我做错了什么?我在文档中发现,在这种情况下应该使用 beginWrite() 和 commitWrite() 方法。
【问题讨论】:
标签: ios swift swift3 realm cllocation