Created
June 6, 2013 19:54
-
-
Save wader/5724410 to your computer and use it in GitHub Desktop.
setValue:forKey: for readonly property test
This file contains hidden or 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 Test1 : NSObject | |
| @end | |
| @implementation Test1 | |
| - (id)retain { | |
| return [super retain]; | |
| } | |
| - (oneway void)release { | |
| [super release]; | |
| } | |
| - (void)dealloc { | |
| [super dealloc]; | |
| } | |
| @end | |
| @interface Test2 : NSObject | |
| @property(nonatomic, retain, readonly) Test1 *test1; | |
| @end | |
| @implementation Test2 | |
| - (id)retain { | |
| return [super retain]; | |
| } | |
| - (oneway void)release { | |
| [super release]; | |
| } | |
| - (void)dealloc { | |
| [_test1 release]; | |
| [super dealloc]; | |
| } | |
| @end | |
| int main(int argc, const char * argv[]) | |
| { | |
| @autoreleasepool { | |
| Test2 *test2 = [[[Test2 alloc] init] autorelease]; | |
| [test2 setValue:[[[Test1 alloc] init] autorelease] forKey:@"test1"]; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment