Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use Cocoa bindings for my latest project?

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.

like image 604
Lawrence Johnston Avatar asked Nov 10 '08 16:11

Lawrence Johnston


1 Answers

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
like image 106
Peter Hosey Avatar answered Jan 03 '23 18:01

Peter Hosey