commitWrite(withoutNotifying failing to mute notifications


#1

I am seeing an issue where notifications I am trying to mute on commit are still being activated after a write is committed.

I have checked, by breakpointing, that notifications are created, and the write started/stopped, on the same, main, thread. I do not know what else to check.

My architecture: I have wrapped Realm inside my data model. The data model exposes standard swift Arrays to the outside world and maps these to Realm Lists internally. The Arrays are lazy loaded, and set up notifications to observe the Lists when they are loaded.

This is an example of an Array on one of my data objects:

@objc dynamic public internal(set) lazy var subPoints: [ECPointData] = {
        subPointLinksObservation = subPointLinks.observe({ [unowned self] changes in
            self.asyncUpdateMappingKey(subPointKey, with: changes, to: self.subPointLinks)
        })
        
        return Array(subPointLinks.map { $0.pointData })
    }()

If I directly update a data object from my UI, I update the mapped Array immediately after a transaction so that the UI reacts correctly, and I mute the associated notification.

This is my end transaction implementation. transactionActions are an Array of closures that do the work of the mutedNotification closures:

public func endTransaction()
    {
        assert(realm.isInWriteTransaction)
        mutedNotifications.forEach { print("Muting: \($0)") }
        try! realm.commitWrite(withoutNotifying: mutedNotifications)
        transactionActions.forEach { $0() }
    }

This is the output I get from an action that inserts an object into two Lists:

Muting: <RLMCancellationToken: 0x600000d506f0>
Muting: <RLMCancellationToken: 0x600000c5f240>
Async host update: Optional(<RLMCancellationToken: 0x600000ca29d0>)
Async host update: Optional(<RLMCancellationToken: 0x600000c5f240>)
Async host update: Optional(<RLMCancellationToken: 0x600000d56ac0>)
Async subPoints update: Optional(<RLMCancellationToken: 0x600000d506f0>)

As you can see, the muted notifications are being called, as well as two other expected calls, after the write is committed.

Can anyone suggest further avenues of investigation? I can’t see anyone else noting that this doesn’t work, so I assume I am making a mistake somewhere.

Thank you.


#2

Did you ever figure out this one? I have a similar issue – only it doesn’t even happen every time.