본문 바로가기
ios

Error: realm accessed from incorrect thread

by 고고 2021. 11. 19.
realm accessed from incorrect thread,
cannot construct reference to unmanaged object, which can be passed across threads directly

 

안녕하세요 ◠‿◠ 고고입니다.

스택오버플로우를 보다보니

‘you should never try to use let realm = try! Realm() to create a singleton Realm instance and than try to access that everywhere from your app.’
let realm = try! Realm()

저거를 하나로 두고 여러 개의 함수에서 불렀던 게 문제였습니다.

 

‘The best way to use Realm in a thread-safe way is to create a new reference to your Realm using let realm = try! Realm() every time you move between threads and need to access your Realm. This way you can ensure that you will never get the incorrect thread exception.’

 

thread-safe하려면 매번 realm에 접근할 때마다 새로운 참조를 하는 게 가장 좋습니다. (매번 저 코드를 함수 안에 넣어주어야 함.)

 

 

스택오버플로우 : https://stackoverflow.com/questions/45375468/realm-thread-safe-object-with-singleton

'ios' 카테고리의 다른 글

GCD에서 의도치 않은 교착상태를 피하는 법  (0) 2021.12.22
DispatchQueue 교착상태  (0) 2021.12.22
DispatchQueue 종류 세 가지  (0) 2021.12.21
동기/비동기, 직렬/동시  (0) 2021.12.21
[iOS] Carthage 전환 후기  (0) 2021.11.18

댓글