Skip to content

Instantly share code, notes, and snippets.

@markSci5
Created August 21, 2013 11:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markSci5/6293061 to your computer and use it in GitHub Desktop.
Save markSci5/6293061 to your computer and use it in GitHub Desktop.
Assigning ui element to weak property
@property (nonatomic, weak) KGModalContainerView *containerView;
...
-(void)viewDidLoad {
[super viewDidLoad];
KGModalContainerView *myContainerView = [[KGModalContainerView alloc] initWithFrame:containerViewRect]; // This is a strong reference to that view
[self.view addSubview:myContainerView]; //Here self.view retains myContainerView
self.containerView = myContainerView; // Now self.containerView has weak reference to that view, but if your self.view removes this view, self.containerView will automatically go to nil.
// In the end ARC will release myContainerView, but it's retained by self.view and weak referenced by self.containerView
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment