Skip to content

Instantly share code, notes, and snippets.

@kylesluder
Created February 15, 2012 23:44
Show Gist options
  • Save kylesluder/1840134 to your computer and use it in GitHub Desktop.
Save kylesluder/1840134 to your computer and use it in GitHub Desktop.
Unexpected readonly/readwrite @Property and @synthesize behavior
#import <Foundation/NSObject.h>
@interface Foo : NSObject
@property (readonly, assign) id bar;
@end
@interface Foo (Internal)
@property (readwrite, assign) id bar;
@end
@implementation Foo
@synthesize bar=_bar;
@end
int main(int argc, char **argv)
{
@autoreleasepool {
Foo *f = [[Foo alloc] init];
f.bar = @"Hello";
[f release];
}
return 0;
}
/*
* % clang -v
* Apple clang version 3.0 (tags/Apple/clang-211.12) (based on LLVM 3.0svn)
* Target: x86_64-apple-darwin11.3.0
* Thread model: posix
* % clang -o proptest proptest.m -framework Foundation
* % proptest
* 2012-02-15 15:39:23.199 proptest[4617:707] -[Foo setBar:]: unrecognized selector sent to instance 0x10d513530
* 2012-02-15 15:39:23.202 proptest[4617:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Foo setBar:]: unrecognized selector sent to instance 0x10d513530'
* *** First throw call stack:
* (
* 0 CoreFoundation 0x00007fff8892afc6 __exceptionPreprocess + 198
* 1 libobjc.A.dylib 0x00007fff85460d5e objc_exception_throw + 43
* 2 CoreFoundation 0x00007fff889b72ae -[NSObject doesNotRecognizeSelector:] + 190
* 3 CoreFoundation 0x00007fff88917e73 ___forwarding___ + 371
* 4 CoreFoundation 0x00007fff88917c88 _CF_forwarding_prep_0 + 232
* 5 proptest 0x000000010d4aee86 main + 134
* 6 proptest 0x000000010d4aedd4 start + 52
* 7 ??? 0x0000000000000001 0x0 + 1
* )
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment