Hi guys!
We have an Observer pattern (aka Java Listener) implemented in Common code.
Subscriber adds a function to the Observer. The function receives events from the Observer.
In the end Subscriber is responsible to remove the listening function from the Observer.
Now we are trying to use the Observer on iOS with Swift functions.
But it’s not working as expected.
The Swift function hash-code is different on each request.
It seems KMM creates a wrapper object for a Swift function on each request.
So addListener() and removeListener() receive different Objects for the same Swift function.
It becomes impossible to remove a function from the Observer.
Do you have any advice how to implement Observer in KMM?
j
jw
07/25/2023, 12:34 PM
Return a handle object from add on which you can call remove
👍 2
p
Pavel Repkin
07/25/2023, 1:10 PM
Thank you, Jake! Looks like a solid alternative /star struck