Changing Models with Key-Value Observing

Making our model code flexible is the low-hanging fruit, and keeping a view up-to-date with a model is usually a hard problem. A model object has to be aware of all the views accessing its data, which just leads to all sorts of problems and code spaghetti. Imagine a world where it all just works: you change the name on a User, and the appropriate label instantly reflects those changes...no code spaghetti or zero-ing references.

I’m talking this up so much because it is possible to implement. iOS has a concept of key-value observing (KVO). Built into the frameworks is a system by which one object can passively observe changes in properties of another object. Those properties are referred to by keys

Get RubyMotion now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.