피트니스 트래커 앱에서 현재 실행 기록을 저장하고 실행이 발생한 위치 이름을 가져 오는 역 지오테이션 방법을 호출합니다.RealmSwift - 쓰기 시작/커밋
먼저 나는 쓰기 '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()
})
}
는 예외
Terminating app due to uncaught exception 'RLMException', reason: 'The Realm is already in a write transaction'
와 결과 무엇 내가 틀렸어? 내가 문서에서 발견 한 것은 beginWrite()
과 commitWrite()
메쏘드가이 경우에 사용되어야한다는 것입니다. 그들은 둘 다 "기록 세션"을 열고, 같은 일을 단지
try! realm.write {
전에
지금 나는 치명적인 오류가있다 : '시도!' 표현식이 예기치 않게 오류를 발생 시켰습니다. Error Domain = io.realm Code = 1 "존재하지 않는 쓰기 트랜잭션을 커밋 할 수 없습니다." ' – DCDC
'행을 남겨 뒀기 때문입니다! realm.commitWrite()'. 또한 삭제해야합니다. –