Created
March 12, 2012 16:09
-
-
Save hartbit/2023025 to your computer and use it in GitHub Desktop.
ARC weak weird behavior
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
| @interface Child : NSObject | |
| @property (nonatomic, weak, readonly) Parent* parent; | |
| - (id)initWithParent:(Parent*)parent; | |
| @end |
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 "Child.h" | |
| @interface Child () | |
| @property (nonatomic, weak) Parent* parent; | |
| @end | |
| @implementation Child | |
| @synthesize parent = _parent; | |
| #pragma mark - Initialization | |
| - (id)initWithParent:(Parent*)parent | |
| { | |
| if ((self = [super init])) | |
| { | |
| [self setParent:parent]; | |
| } | |
| return self; | |
| } | |
| @end |
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
| Parent* parent = [Parent new]; | |
| Child* child = [[Child alloc] initWithParent:parent]; | |
| NSAssert([child parent] == parent, nil); // ERROR: [child parent] == nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment