How to integrate KVC in MVC?

Posted by Paperflyer on Stack Overflow See other posts from Stack Overflow or by Paperflyer
Published on 2010-03-31T14:25:25Z Indexed on 2010/04/01 0:13 UTC
Read the original article Hit count: 797

So I have an MVC-application in Cocoa.
There are some custom views, a controller and a model. Of course, the views need to know some stuff, so they get their data from the controller. However, they do not use accessors in the controller, they use KVC with a keypath that calls right through to the model:

// In view.m
time = [timeSource valueForKeyPath:@"theModel.currentTime"];
// timeSource is a pseudo-delegate of the view that holds the controller

This simplifies things a great deal and technically, the views still don't know the model in person (that is, in pointer). But of course, they access it directly.

Is that a usual (or at least sensible) usage of KVC and MVC?
Or how would you implement this kind of communication?

© Stack Overflow or respective owner

Related posts about key-value-coding

Related posts about model-view-controller