FROM : Adam R. Maxwell
DATE : Fri Jun 06 23:16:23 2008
On Friday, June 06, 2008, at 02:07PM, "George Stuart" <george.<email_removed>> wrote:
>The suggestion of using a keyPath of @"self" presents another question:
>1) I assume NSSortDescriptor is using valueForKeyPath:, which in
>turns calls valueForKey: some number of times, to get the object for
>the keyPath I specified. Is it defined behavior that sending an
>object valueForKey:@"self" will return the object itself?
I always use self as the key path in cases like this, since -[NSObject self] is documented to return the receiver. It has the advantage of working with objects other than strings.
> I guess
>this is ultimately the same as my original question, "is it defined
>behavior that sending an object valueForKey:nil will return the object
>itself?"
Not as far as I know; I'd expect it to return nil or die with an assertion failure.
--
Adam
DATE : Fri Jun 06 23:16:23 2008
On Friday, June 06, 2008, at 02:07PM, "George Stuart" <george.<email_removed>> wrote:
>The suggestion of using a keyPath of @"self" presents another question:
>1) I assume NSSortDescriptor is using valueForKeyPath:, which in
>turns calls valueForKey: some number of times, to get the object for
>the keyPath I specified. Is it defined behavior that sending an
>object valueForKey:@"self" will return the object itself?
I always use self as the key path in cases like this, since -[NSObject self] is documented to return the receiver. It has the advantage of working with objects other than strings.
> I guess
>this is ultimately the same as my original question, "is it defined
>behavior that sending an object valueForKey:nil will return the object
>itself?"
Not as far as I know; I'd expect it to return nil or die with an assertion failure.
--
Adam
| Related mails | Author | Date |
|---|---|---|
| George Stuart | Jun 6, 10:43 | |
| Ken Thomases | Jun 6, 21:05 | |
| Andrew Merenbach | Jun 6, 21:26 | |
| George Stuart | Jun 6, 23:06 | |
| Adam R. Maxwell | Jun 6, 23:16 | |
| Ken Thomases | Jun 6, 23:51 | |
| Adam R. Maxwell | Jun 7, 00:53 | |
| Kyle Sluder | Jun 9, 05:15 |






Cocoa mail archive

