Should I use Cocoa bindings for my latest project?

前端 未结 7 769
执念已碎
执念已碎 2020-12-25 08:45

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

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-25 09:19

    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:

    • Key-Value Coding (KVC) Programming Guide
    • Key-Value Observing (KVO) Programming Guide
    • Model Object Implementation Guide
    • KVC Accessor Methods (part of the aforementioned KVC Programming Guide) and my complete list of KVC-compliant accessor selector formats

提交回复
热议问题