What is contentObject used for?

  • In ADC doc "Cocoa Bindings Programming Topics" I'm reading

    "NSObjectController exposes a single binding for content called contentObject. You can establish a binding from contentObject to any object that is key-value-coding and key-value-observing compliant for the keys that you intend to have the controller operate on."

    I have previously used the content outlet to establish a connection between NSObjectController and its object. Is contentObject an alternative way to do the same thing or is it used for something else? In what situation would you use the  content outlet and when would you use contentObject?

    Bob

          ____________________________________________________________________________________
    Fussy? Opinionated? Impossible to please? Perfect.  Join Yahoo!'s user panel and lay it on us. http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7
  • On Oct 7, 2007, at 7:31 AM, Bob Ueland wrote:

    > I have previously used the content outlet to establish a connection
    > between NSObjectController and its object. Is contentObject an
    > alternative way to do the same thing or is it used for something
    > else? In what situation would you use the  content outlet and when
    > would you use contentObject?
    >
    You use the binding when you want to bind the value; you use the
    content when you want to set it directly...

    mmalc
  • Apologies for the "newbie" question, but I've been trying to learn
    from this list for a while, but I often get stumped by the terminology
    and phraseology used by more "elite" (no disrespect intended) members.
    What is the difference between a "binding the value" and "setting it
    directly"? What is "it"? a value, an object, an ivar, what? Apologies
    for the silly question.

    Regards,
    Jason Wiggins

    On 08/10/2007, at 12:59 AM, mmalc crawford wrote:

    >
    > On Oct 7, 2007, at 7:31 AM, Bob Ueland wrote:
    >
    >> I have previously used the content outlet to establish a connection
    >> between NSObjectController and its object. Is contentObject an
    >> alternative way to do the same thing or is it used for something
    >> else? In what situation would you use the  content outlet and when
    >> would you use contentObject?
    >>
    > You use the binding when you want to bind the value; you use the
    > content when you want to set it directly...
    >
    > mmalc
  • Jason Wiggins wrote:
    I often get stumped by the terminology and phraseology used by more "elite"...
    What
    is the difference between a "binding the value" and "setting it
    directly"? What is "it"? a value, an object, an ivar, what?

    Thanks Jason, I'm also a newbie and exactly the same questions popped up in my mind.

    I was looking at an example in "Simple Bindings Adoption" at
    http://developer.apple.com/samplecode/SimpleBindingsAdoption/index.html

    I
    was looking at example SimpleBindingsAdoption03. There they use
    contentObject. But I was able to make exactly the same behavior by
    using the content outlet. The one was not harder then the other. So my
    question is still when would you use contentObject and when would you
    use content outlet, or are they more or less equivalent.

    Bob

          ____________________________________________________________________________________
    Fussy? Opinionated? Impossible to please? Perfect.  Join Yahoo!'s user panel and lay it on us. http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7
  • Hi Jason,

    i've just recently dove into the world of Cocoa and Objective-C
    myself and tackling the entire 'Key Value' thingy has been a very
    recent epiphany. So i'll take advantage of you asking that question
    and post a reply. This helps the both of us: either 1) i'm right and
    i will have helped you, thus returning some of the help i've been
    able to enjoy from this list so far or 2) i'm wrong and then surely
    some "elite" (to use your words ;)) member will rebuke me and tell
    you how it's right. :D

    Here we go:
    One of the key paradigmas of object oriented programming is the
    encapsulation of the object's properties. So you'll create getter and
    setter methods for the properties instead of setting them directly.
    Key Value Coding takes this one step further in that you don't even
    call the getter and setter methods yourself anymore but *ask the
    object* to tell you some property's value or to set some property's
    value. So instead of calling the getter directly as in:
    [myObject propertyX]; //first part of this the receiving object of
    the message, second part the message itself (in this case invoking
    the getter for a property called 'propertyX')
    you'll say:
    [myObject valueForKey:@"propertyX"]; //note how now the property is
    an NSString(!!!) and *NOT* the propertyX itself or the name of a
    message to be sent / method to be invoked!

    Same goes the other way when you want to SET a value. So instead of
    calling the setter directly as in:
    [myObject setPropertyX:foo];
    you'll say:
    [myObject setValue:foo forKey:@"propertyX"]; //again, the propertyX
    is being an NSString, used to FIND the proper setter method to be called

    Now one might wonder (i certainly did!) and ask 'why would i wanna
    type that valueForSomething stuff when i can call the getter and
    setters using less letters?' and maybe that's where you are right now?
    The point being is that the entire KeyValue thing can be thought of
    as a 'protocol' and when your classes comply with that 'protocol'
    certain technologies will be unlocked for access and usage (kinda
    like...'DING DING! Level upgrade of your code! You've now unlocked a
    new special skill!'). One of the major things that you'll then be
    able to enjoy is the Key-Value Observing / Binding which can save you
    lots of repetetive coding in the Model-View-Controller thingy between
    your 'Model' and the 'View'.

    At this point i'd recommend that you grab a copy of Aaron Hillegass'
    'Cocoa Programming for Mac OS X'. I'm working through the book myself
    as i'm typing this email and it has helped me tremendously to
    understand many of the technologies that make Cocoa click the way it
    does. But of course the Apple documentation is a rich source of
    knowledge about KeyValueCoding and -Binding, too and there are
    websites dealing with this thing just one Google search away.

    I hope this reply was able to help you understand this thing a bit
    better.

    Cheers,

    Malte Philipp A.

    On 07.10.2007, at 17:10, Jason Wiggins wrote:

    > Apologies for the "newbie" question, but I've been trying to learn
    > from this list for a while, but I often get stumped by the
    > terminology and phraseology used by more "elite" (no disrespect
    > intended) members.
    > What is the difference between a "binding the value" and "setting
    > it directly"? What is "it"? a value, an object, an ivar, what?
    > Apologies for the silly question.
    >
    > Regards,
    > Jason Wiggins
    >
    >
    >
    > On 08/10/2007, at 12:59 AM, mmalc crawford wrote:
    >
    >>
    >> On Oct 7, 2007, at 7:31 AM, Bob Ueland wrote:
    >>
    >>> I have previously used the content outlet to establish a
    >>> connection between NSObjectController and its object. Is
    >>> contentObject an alternative way to do the same thing or is it
    >>> used for something else? In what situation would you use the
    >>> content outlet and when would you use contentObject?
    >>>
    >> You use the binding when you want to bind the value; you use the
    >> content when you want to set it directly...
    >>
    >> mmalc

  • 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
  • mmalc wrote
    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 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).

    Thanks, this make it very clear. I think my main difficulty was that I was not seeing the situation where the content object dynamically changed.

    Bob

          ____________________________________________________________________________________
    Shape Yahoo! in your own image.  Join our Network Research Panel today!  http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7
  • Firstly, apologies to Bob for co-opting his question. Secondly, thank
    you to all for clearing up my understanding of bindings and the use of
    them.

    Regards,
    Jason

    On 08/10/2007, at 3:20 AM, Bob Ueland wrote:

    > mmalc wrote
    > 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 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).
    >
    >
    > Thanks, this make it very clear. I think my main difficulty was that
    > I was not seeing the situation where the content object dynamically
    > changed.
    >
    > Bob
    >
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today