Re: Weird behavior in NSMutableDictionary
Re: Weird behavior in NSMutableDictionary
- Subject: Re: Weird behavior in NSMutableDictionary
- From: mmalcolm crawford <email@hidden>
- Date: Sat, 18 Dec 2004 21:25:41 -0800
On Dec 18, 2004, at 4:06 AM, Jeremy Dronfield wrote:
What you're missing is key value coding. The NSDictionary and
NSMutableDictionary docs are strangely disingenuous in their
definitions for these methods. -valueForKey: and -setValue:forKey: are
not in fact dictionary methods. They are methods in the
NSKeyValueCoding informal protocol, which is implemented by NSObject.
That they are defined in the NSKeyValueCoding informal protocol does
not mean they are not dictionary methods. As Steven noted, they are in
fact overridden, as the documentation makes clear.
Note, however, that the documentation is not completely accurate
regarding the implementation of -valueForKey:. The current
documentation states that it simply calls -objectForKey:. This is
clearly not the case (see below). A bug report has been filed.
(See also analogous situation for NSArray:
<http://www.cocoabuilder.com/archive/message/cocoa/2004/11/27/122494>.)
mmalc
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSDictionary *dict = [NSDictionary dictionaryWithObject:@"hello"
forKey:@"greeting"];
NSLog(@"count %@", [dict objectForKey:@"@count"]);
NSLog(@"value %@", [dict valueForKey:@"@count"]);
NSLog(@"allKeys %@", [dict valueForKey:@"@allKeys"]);
[pool release];
return 0;
}
->
count (null)
value 1
allKeys (greeting)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden