• 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: What is contentObject used for?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What is contentObject used for?


  • Subject: Re: What is contentObject used for?
  • From: mmalc crawford <email@hidden>
  • Date: Sun, 7 Oct 2007 09:20:43 -0700


On Oct 7, 2007, at 8:10 AM, Jason Wiggins wrote:

What is the difference between a "binding the value" and "setting it directly"? What is "it"? a value, an object, an ivar, what?

Per Cocoa Bindings Programming Topics > What Are Cocoa Bindings?
In the simplest functional sense, the Cocoa bindings technology provides a means of keeping model and view values synchronized without you having to write a lot of “glue code.” It allows you to establish a mediated connection between a view and a piece of data, “binding” them such that a change in one is reflected in the other.


[...]

What Is a Binding?
A binding is an attribute of one object that may be bound to a property in another such that a change in either one is reflected in the other. For example, the “value” binding of a text field might be bound to the temperature attribute of a particular model object. More typically, one binding might specify that a controller object “presents” a model object and another binding might specify that the value of a text field be tied to the temperature property of the object presented by the controller.




If you set the contentObject of an object controller, then -- just as anywhere else in Cocoa -- you're setting one of its properties (typically an instance variable) and it's then the recipient's responsibility to look after it.
If you want to change the content object (that is, provide a different object rather than simply modifying properties of the object itself) you have to set the contentObject again (glue code).



If you bind the contentObject, they you're telling it to keep it synchronised with whatever is at the end of the keypath you provided from the source object. So if you have a document with an instance variable 'mainObject' and you bind an object controller's contentObject to [Document].mainObject, then if you set (in a KVO- compliant way) a new object for mainObject, the controller's content will be automatically updated to be this new object (contrast the non- bindings situation where you would have to send a setContent: message yourself).


Per a recent message here, in many simple cases there would be little reason to bind the content rather than simple set it directly, except that it's possible to establish the binding in IB without any code -- whereas if you wanted to set it directly you'd have to write code.

mmalc

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >What is contentObject used for? (From: Bob Ueland <email@hidden>)
 >Re: What is contentObject used for? (From: mmalc crawford <email@hidden>)
 >Re: What is contentObject used for? (From: Jason Wiggins <email@hidden>)

  • Prev by Date: Re: What is contentObject used for?
  • Next by Date: Re: What is contentObject used for?
  • Previous by thread: Re: What is contentObject used for?
  • Next by thread: Re: What is contentObject used for?
  • Index(es):
    • Date
    • Thread