This is not a duplicate question, please just continue reading!
I'm getting the "'RLMException', reason: 'Realm accessed from incorrect thread'" error message displayed when I use my RealmBackend
singleton in a DispatchQueue.
This is my class:
class RealmBackend {
static let shared = RealmBackend()
var realm = try? Realm()
}
There are functions in it like addObject()
which are accessing the realm.commitWrite()
and the realm.beginWrite()
functions.
Now I call the addObject
function from a callback (UIRefreshControl
) with the DispatchQueue.main.sync
since I'm assuming the Realm object was created on the main
Thread (I read somewhere on Github that you need the same Threads for instantiating and accessing the Realm()
value).
As I stated before I always get this RLMException
, has someone faced the same problem?