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, 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:

 App Development, Development

Matthew's Blog
Home   Blog   LinkedIn   Contact Me
Connect on LinkedIn, Google+,
Current focus: App & Web Development
Preferred Environments: OS X, iOS, Xcode, Sublime Text
Current skills: SWIFT, Objective-C, iOS SDK, CoreData, CoreAudio, JavaScript, HTML5, CSS, Wordpress
Degree: Bachelors of Science in Computer Information Systems Technology
from PURDUE University

© Website by Matthew Fecher
Denver, Colorado, USA.