Created
February 11, 2014 13:25
-
-
Save tarunon/8934732 to your computer and use it in GitHub Desktop.
NSArray's valueForKey is very convenient! :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface NSArray (objectForKeyedSubscript) | |
- (id)objectForKeyedSubscript:(id)key; | |
@end | |
@implementation NSArray (objectForKeyedSubscript) | |
- (id)objectForKeyedSubscript:(id)key | |
{ | |
return [[self valueForKey:key] firstObject]; | |
} | |
@end | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
NSArray *ary = @[@{@"AAA": @"BBB"}]; | |
NSLog(@"%@", ary[@"AAA"]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment