[에러] Terminating app due to uncaught exception 'NSInternalInconsistencyException' 해결

‍deprecated·2021년 8월 6일
1

Swift 에러 해결

목록 보기
1/1


*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.'

Collection View를 reloadData() 하는 부분에서 시간이 매우 오래걸리더니 이 에러를 출력하고 죽어버렸다.
이유를 곧이곧대로 해석해보면, 레이아웃 엔진의 수정은, main 스레드에서 한번 접근이 이루어졌다면 그 후로는 절대 background 스레드에서 행해지면 안된다는 말이었다.
다시 말하면 background 스레드가 아닌 main 스레드 에서 접근해야 한다는 말!

해당 에러가 난 부분을
DispatchQueue.main.async{ }
또는
DispatchQueue.main.sync{ }로 감싸주니 해결되었다. (둘 다 되었다.)

profile
deprecated

0개의 댓글