开发者

How to integrate KVC in MVC?

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 t开发者_开发百科hings 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?


It seems awfully close to "knowing" the model to me. I don't know how most people do it, but I would be more likely to make properties on the controller. The reason I would avoid that, is that if you change the model, the views break. As I understand it, one of the main strengths of MVC is that if you change the model, you don't have to change the view.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜