NSDictionary -objectAtKeyedSubscript equiv. to -objectForKey, not -valueForKey:

Originator:chaos42
Number:rdar://14226440 Date Originated:21-Jun-2013 12:36 AM
Status:Duplicate/11935544 Resolved:
Product:Documentiation Product Version:10.8/2012-7-17
Classification:Other Bug Reproducible:Always
 
Summary: The NSDictionary documentation in the 10.8 SDK says that -objectForKeyedSubscript: "is the same as -valueForKey:", however, when linked against the 10.8 SDK and run on OS X 10.9, it actually calls -objectForKey: instead of -valueForKey:. This is easily seen by testing the discussion section of -valueForKey:
"If key does not start with “@”, invokes objectForKey:. If key does start with “@”, strips the “@” and invokes [super valueForKey:] with the rest of the key." This does not happen when calling dict[@"@foobar"];

Steps to Reproduce:
1. Read the NSDictionary documentation
2. Create a Command Line app > Foundation Tool
3. in main.m, select all and paste the following: 
#import <Foundation/Foundation.h>

NSString *globalFoobar;

@interface NSDictionary (Extra)
@property (nonatomic, strong) NSString *foobar;
@end
@implementation NSDictionary (Extra)

-(NSString *)foobar
{
    return globalFoobar;
}
-(void)setFoobar:(NSString *)foobar
{
    globalFoobar = foobar;
}
@end

int main(int argc, const char * argv[])
{

    @autoreleasepool {
        NSDictionary *someDict = [[NSDictionary alloc] init];
        someDict.foobar = @"Baz";
        NSLog(@"%@", someDict[@"@foobar"]);
    }
    return 0;
}
4. Build and run.

Expected Results: Outputs 
2013-06-21 00:26:44.028 SubscriptingTest[3384:303] Baz

Actual Results:
2013-06-21 00:26:44.028 SubscriptingTest[3384:303] (null)

Regression: Unknown

Notes: It's possible this is a functionality bug rather than a documentation but, but either way, it should be fixed.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!