An Observable Pattern Implementation in Swift
colindrake.me
colindrake.me
The raw data is on GitHub: https://github.com/melling/SwiftResources
The new trend favoring Swift value types often leads to reinventing the wheel for the sake of premature optimization.
Holding a ref to the subscriber so that it can be unsubscribed.
So a subscription needs a method to call when the value changes. And the method needs to pass the new value.
Being unsubscribed isn't enough because if I really care about the object I need to know when it goes away, not just be magically unsubscribed from it and continuing in my own little fantasy land where the object still exists.
Edit:
Continuing the thought, I think the model needs two protocols -- a publisher and a subscriber. The subscriber automatically cancels subscriptions when it goes away and the publisher automatically cancels subscriptions when it goes away. The information passed in a given case is simply what object and property I am subscribing to (since, as a subscriber I already know who I am, and the information can be encapsulated without being passed).
And I'm not even sure how you'd implement what you are talking about without tracking your subscribers. How does it automatically go away? Weak references with the subscriber implementing a protocol? It's now gotten more complicated than what the original author has proposed. imho.
https://github.com/ReactiveCocoa/ReactiveCocoa/blob/master/R...