• 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: email@hidden
  • Date: Sun, 7 Oct 2007 18:13:06 +0200

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

_______________________________________________

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:
40optusnet.com.au


This email sent to email@hidden

_______________________________________________

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:
40mac.com


This email sent to email@hidden


_______________________________________________

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


  • 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