Is it possible to observe iOS NSObject value changes with Kotlin/Native

Viewed 359

I am trying to implement an observer for changes to a value for a give key in UserDefaults from the ios native part of a multiplatform project written in Kotlin/Native. Here is the code that I wrote:

fun subscribeForDataChange(storeName: String, callback: () -> Unit) {
        NSUserDefaults(storeName).addObserver(
            object : NSObject() {
                fun observeValue(
                    observer: NSObject,
                    forKeyPath: String,
                    options: NSKeyValueObservingOptions,
                    context: COpaquePointer?
                ) {
                    callback()
                    print("Data Changed!!!")
                }
            },
            options = NSKeyValueObservingOptionNew,
            forKeyPath = DATA_KEY,
            context = null
        )

    }

The problem is that I never get a notification, most probably because the observeValue is not defined in NSObject, but what else should I do to achieve that?

1 Answers
Related