我应该使用Cocoa绑定我的最新项目吗? [英] Should I use Cocoa bindings for my latest project?

查看:112
本文介绍了我应该使用Cocoa绑定我的最新项目吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始一个项目,我认为会受益于绑定(我有一个源列表表,几个浏览器视图等),但我认为它也将是可行的,也许更容易理解,没有他们。从我有限的经验,我发现绑定是很难排除故障,非常魔法(例如,很难在任何地方插入日志,找出哪里的东西破碎,一切都行或不行)。



这只是我不经验的谈话(在这种情况下,我可以坐下来花一些时间,只是我的理解绑定,期望事情开始变得更清楚/更容易)或者我会更好

解决方案

使用绑定。

/ p>

请注意,您必须按照MVC模式才能从绑定中获得最大收益。 这似乎比看起来容易,因为Cocoa几乎为你现在做了一切:


  1. 查看: NSView 和子类(当然), NSCell 和子类, NSWindow

  2. 控制器: NSController 和子类(特别是 NSArrayController

  3. 模型:Core Data

如果您不打算使用Core Data,滚动自己的模型对象,但这很容易。大多数这些对象的方法将是简单的访问器,如果你的目标是Leopard,你可以 @synthesize



推荐阅读:

$ b,你不能写任何代码,
$ b

I'm starting a project which I think would benefit from bindings (I've got a source list table, several browser views, etc), but I think it would also be quite doable, and perhaps more understandable, without them. From my limited experience I've found bindings to be difficult to troubleshoot and very "magic" (e.g. it's difficult to insert logging anywhere to figure out where stuff is breaking, everything either works or it doesn't).

Is this just my inexperience talking (in which case I could sit down and spend some time just working on my understanding of bindings and expect things to start becoming clearer/easier) or would I be better off just writing all the glue code myself in a manner which I was sure I could understand and troubleshoot.

解决方案

Use Bindings.

Note that you must follow the MVC pattern to get the most from bindings. This is easier than it seems, as Cocoa does almost everything for you nowadays:

  1. View: NSView and subclasses (of course), NSCell and subclasses, NSWindow and subclasses
  2. Controller: NSController and subclasses (especially NSArrayController)
  3. Model: Core Data

If you're not going to use Core Data, then you get to roll your own model objects, but this is easy. Most of these objects' methods will be simple accessors, which you can just @synthesize if you're targeting Leopard.

You usually can't get away with not writing any code, but Bindings can enable you to write very little code.

Recommended reading:

这篇关于我应该使用Cocoa绑定我的最新项目吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆