• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Cocoa bindings one- or bi-directional
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa bindings one- or bi-directional


  • Subject: Re: Cocoa bindings one- or bi-directional
  • From: Kay Roepke <email@hidden>
  • Date: Thu, 26 May 2005 20:51:54 +0200


On 26. May 2005, at 16:34 Uhr, Zdzislaw Losvik wrote:

I am stuck with that for a longer while.

I thought that binding two objects together causes each of them to be updated when the other gets updated.
Here is a simple example with to model objects bound to each other:


BinderBrick *brick1 = [[BinderBrick alloc] init];
BinderBrick *brick2 = [[BinderBrick alloc] init];
[brick1 bind:@"intValue" toObject:brick2 withKeyPath:@"intValue" options:nil];


    [brick1 setIntValue:5];
    NSLog(@"%d, %d", brick1->_intValue, brick2->_intValue);

    [brick2 setIntValue:7];
    NSLog(@"%d, %d", brick1->_intValue, brick2->_intValue);

The output is:
2005-05-26 16:08:12.436 Binder[1357] 5, 0
2005-05-26 16:08:12.437 Binder[1357] 7, 7

This is correct behavior. You tell brick1 to observe changes on the keypath intValue of the object brick2.
brick2 doesn't know anything about brick1 - that wouldn't be really helpful, would it?
If you want it the other way round, you'll need to tell brick2 what to observe, too.


Review http://developer.apple.com/documentation/Cocoa/Conceptual/ KeyValueObserving/index.html for in-depth info and
http://developer.apple.com/documentation/Cocoa/Conceptual/ CocoaBindings/index.html for the overview.


On a side note: I hope you don't use "brick1->_intValue" in your normal code?

HTH,

Kay
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Cocoa bindings one- or bi-directional
      • From: mmalcolm crawford <email@hidden>
References: 
 >Cocoa bindings one- or bi-directional (From: Zdzislaw Losvik <email@hidden>)

  • Prev by Date: drawRect is getting the wrong Rectangle
  • Next by Date: Re: reordering NSTableView elements
  • Previous by thread: Cocoa bindings one- or bi-directional
  • Next by thread: Re: Cocoa bindings one- or bi-directional
  • Index(es):
    • Date
    • Thread