Is Realm write to a file is synchronous?

So I’m using realm.write { ... } to perform changes in the database but I want to know when they are persisted in a file. I assume file write is async and may happen some time after realm.write {} is performed. Am I right? If so is there a callback for that operation?

realm.write as synchronous. It’s essentially a wrapper around realm.beginWrite and realm.commitWrite. Very important that to avoid blocking the UI, you do these on a background thread. But…

Realm, 10.25 and above support sawait async formatted calls but I think you’re most interested in asynchronous writes. See writeAsync

Unfortunately, the documentation is a bit thin when it comes to async calls (Realm team???), so a lot of discovery is by trial and error.

example use

let p = PersonClass() = "Jay"
}, onComplete: { error in
    if let err = error {

    print("data was saved")
1 Like

Well, my assumption was that file write might be async even for a sync write and continue after write is committed. Though, I checked it in the playground project and it looks like it performed sync so my assumption was wrong

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.