One of the things I enjoy in open source contributions is discovering various tips in a fun environment. In this instance, I was porting some Objective-C to Swift for one of my favorite open source projects, AudioKit.io. The original contributors had used a KVO pattern in Objective-C. Since I wanted to stay true to their vision, I quickly sought off to implement the same in Swift.
The original Objective-C version of the class contained some properties to observe:
@property float horizontalPercentage; @property float verticalPercentage;
For Swift to observe the same properties, you must add the “dynamic” keyword:
dynamic var horizontalPercentage: Float dynamic var verticalPercentage: Float
To learn more about this project and see my full code:
To learn more about KVO in Swift, check this Stack-Overflow thread:
Home Blog LinkedIn Contact Me