Skip to content

Instantly share code, notes, and snippets.

@ddribin
Created April 24, 2009 15:42
Show Gist options
  • Save ddribin/101153 to your computer and use it in GitHub Desktop.
Save ddribin/101153 to your computer and use it in GitHub Desktop.
// gcc -o undefined-key undefined-key.m -framework Foundation
#import <Foundation/Foundation.h>
@interface Foo : NSObject { }
@end
@implementation Foo
#if 1
- (id)valueForUndefinedKey:(NSString *)key
{
NSLog(@"%@: undefined key: %@", [self className], key);
fprintf(stderr, "%s: undefined key: %s\n", [[self className] UTF8String], [key UTF8String]);
return nil;
}
#endif
@end
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Foo * foo = [[[Foo alloc] init] autorelease];
id value = [foo valueForKey:@"bar"];
NSLog(@"value: %@", value);
value = [foo mutableSetValueForKey:@"bar"];
NSLog(@"mutable value: %@", value);
[pool drain];
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment