One of the issues you’ll notice when using Swift is that native key-value-observing is not available and only works with NSObject subclasses.
Swift is changing rapidly and a solution does appear to be on the roadmap for this issue. Until the solution arrives here’s a tutorial from Krzysztof Zablocki illustrating a nice technique for implementing observable properties completely using Swift. This technique uses generics and what’s really nice is that you can create the observable properties without affecting the rest of your code.
You can find the tutorial on the Merowing blog.
A playground demonstrating the technique can be found on Github here.
A nice simple technique for implementing KVO in Swift.
- Open Source Library Providing Basic Generics Within Objective-C
- Tutorial: Avoiding Issues When Moving From Objective-C To Swift
- Tutorial: Creating A Candy Crush Style Game In Swift With Sprite Kit
- Extensive Swift Utility Library Inspired By Python’s Standard Library
- Open Source iOS Component For Creating Great Looking Custom Alert Views Made With Swift
Original article: Tutorial: Using Generics To Implement KVO In Swift
©2014 iOS App Dev Libraries, Controls, Tutorials, Examples and Tools. All Rights Reserved.




