Re: How To: translate column identifier in table view to message selector
Re: How To: translate column identifier in table view to message selector
- Subject: Re: How To: translate column identifier in table view to message selector
- From: Bill Cheeseman <email@hidden>
- Date: Wed, 26 Nov 2003 07:59:40 -0500
on 2003-11-26 7:28 AM, Frank at email@hidden wrote:
>
Running through multiple if statements with
>
string comparisons doesn't seem very efficient. So I tried to look at
>
the alternative of creating a dictionary with selectors as values and
>
strings as keys.
Wouldn't you expect key-value coding in the dictionary to be a little bit
slower than chained if statements? I use chained if statements for my
columns, and the table works plenty fast enough even though a lot of code is
executed.
However, to answer your question, you can use key-value coding to call
methods without using a dictionary. Just declare the messages in your data
source class with the same name as the column identifiers, and make sure
their signatures are the same as typical accessor methods; that is, that
they return an object value and take no parameters. Then -getObject:forKey:,
using the identifier as the key, will call the accessor method and return
its value. Basically, the class itself is treated as a dictionary, and
key-value coding is used to select the desired method. This is how
AppleScript works in Cocoa.
Although accessor methods usually return the value of matching instance
variables, there is nothing that requires them to do that. If the accessor
method instead calls a Core Foundation function or does some elaborate
calculation to return an object value, it will still be called via key-value
coding and return its value. You can do the same thing with 'set' accessor
methods and the -takeValue... method.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
The AppleScript Sourcebook -
http://www.AppleScriptSourcebook.com
Vermont Recipes -
http://www.stepwise.com/Articles/VermontRecipes
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.