O'Reilly logo

RubyMotion by Clay Allsopp

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required