Bindings vs the code way

Discussion in 'Mac Programming' started by Samppaa, Jun 11, 2010.

  1. Samppaa macrumors regular

    Joined:
    Mar 26, 2010
    #1
    I was reading my book the cocoa for mac osx third edition aaron hillegasse book and I read about bindings, I somehow find it more confortable to do in the codeway is there really a difference or do I have to force myself to use bindings :S
     
  2. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #2
    Take a checkbox. With bindings you bind it to some BOOL property. Without bindings, you make it an IBOutlet, you have to initialise its state when the nib file is loaded, change it when the property changes, and add an IBAction that switches its state around. A lot more work.

    You can do it either way, but bindings make it easier.
     
  3. Samppaa thread starter macrumors regular

    Joined:
    Mar 26, 2010
    #3
    I worked with bindings on tavleviews and that stuff, felt that it's more easy to do it in codeway.
     
  4. GorillaPaws macrumors 6502a

    GorillaPaws

    Joined:
    Oct 26, 2003
    Location:
    Richmond, VA
    #4
    The jury's still out on best practices for using bindings. They can be a real pain to debug, which is why many people like to use them for simple things such as gnasher729's suggestion. When working with NSTableViews and other more complex views, many people prefer to use old-school delegation.

    And of course you can always bind things programatically using bind: toObject: withKeyPath: options:.
     
  5. garethlewis2 macrumors 6502

    Joined:
    Dec 6, 2006
    #5
    GorillaPaws are you sure about that?

    Considering the ease of use with bindings, I find it hard to believe that anyone would rather roll their own code than using the NSArrayController and other classes.

    On the other hand, just using NSArrayController and bindings without understanding how it works, is naive and I wouldn't encourage that.
     
  6. GorillaPaws macrumors 6502a

    GorillaPaws

    Joined:
    Oct 26, 2003
    Location:
    Richmond, VA
    #6
    Several well-respected Cocoa programmers have expressed this view. I know some have even gone through the trouble of ripping out most of the bindings.
     
  7. garethlewis2 macrumors 6502

    Joined:
    Dec 6, 2006
    #7
    Fair enough.

    Don't agree with it myself though.
     
  8. GorillaPaws macrumors 6502a

    GorillaPaws

    Joined:
    Oct 26, 2003
    Location:
    Richmond, VA
    #8
    Bindings are just a tool. They can save a lot of code and are really terrific (especially for simple tasks). But they do add to the "behind-the-scenes" complexity, and can make debugging more complicated interactions harder. There's a tradeoff there that some people are cool with while others aren't.

    As an example, I'm building an iTunes-like app that has and source list NSOutlineView which uses delegation, and I plan to use bindings for the tableViews bound to an NSArrayController managing Core Data objects.
     

Share This Page