Crash after updating realm

Hello Realm Team ,
I am facing issue when updating realm object. Realm object updated successfully then got crash

Here is my code

func didUpdatedPills(pillAmount: Int, isAlarm: Bool) {
        try! appDelegate.realm!.write {
            if medObj.pillsIntStock.value != pillAmount{
                medObj.pillsIntStock.value = pillAmount

            if medObj.refillRemainder.value != isAlarm{
                medObj.refillRemainder.value = isAlarm


And Crash

libc++abi.dylib: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception ‘RLMException’, reason: ‘Realm accessed from incorrect thread.’
terminating with uncaught exception of type NSException
CoreSimulator 732.18.0.2 - Device: iPhone 12 Pro Max (07EE0930-EF65-4C15-ADED-C5F7EF67DB8C) - Runtime: iOS 14.2 (18B79) - DeviceType: iPhone 12 Pro Max

Hi @Muhammad_Awais,

how are you calling this function – e.g., from the main thread or in a callback?

call back and initialising realm on appDelegate using OpenSync

The exception is indicating that you’re attempting to work with the realm from a thread other than the one that opened it.

If the realm was opened in the main thread then you could try wrapping your callback code inside a DispatchQueue.main.async { ... } block.

Resolved i was using realm object in another thread

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