• 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: Weird behavior in NSMutableDictionary
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Re: Weird behavior in NSMutableDictionary (From: Harilaos Skiadas <email@hidden>)
 >Re: Weird behavior in NSMutableDictionary (From: Jeremy Dronfield <email@hidden>)

  • Prev by Date: Re: Key-value coding and dictionaries (was Re: Weird behavior in NSMutableDictionary)
  • Next by Date: Re: How do you receive a BOOL from a method returning BOOL
  • Previous by thread: Re: Key-value coding and dictionaries (was Re: Weird behavior in NSMutableDictionary)
  • Next by thread: Re: Weird behavior in NSMutableDictionary
  • Index(es):
    • Date
    • Thread