Hello,
Trying to notify my swift classes when a enum (with associated values) property changes, and found that all my objective-c tricks failed for swift...
First tried KVO: not working since the property is not an objective-c compatible type
Then tried NSNotification in didSet, still not able to do it, since the userInfo only take [NSObject: AnyObject].
The raionale, as I understood, is that these types have no coresponding representation in objective-c, thus the lowest denominator. So how should one propagate changes in Swift land? Will there be swift-only API that can extend these feature to native swift types? Maybe there are some elegant solutions out there already? Does anybody encounter similar situations and how do you resolve it?
[update]
After moving beyond the userInfo, bumped into more Notification system's AnyObject constraint in both addObserver and postNotification API. Which means not only a struct can't send notification natively, it can't observe any notification either without "pretending" to be a class... Basically NSNotificationCenter doesn't know how to deal with swift value types. If swift value types can carry behavior and indeed have valid "identity" in the system, I am not sure why these objetive-c systems (such as Notification, KVO) shouldn't evovle to handle them, at least as an opague instance? ...