Skip to content

Instantly share code, notes, and snippets.

@hartbit
Created March 12, 2012 16:09
Show Gist options
  • Select an option

  • Save hartbit/2023025 to your computer and use it in GitHub Desktop.

Select an option

Save hartbit/2023025 to your computer and use it in GitHub Desktop.
ARC weak weird behavior
@interface Child : NSObject
@property (nonatomic, weak, readonly) Parent* parent;
- (id)initWithParent:(Parent*)parent;
@end
#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
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