Permalink
Browse files

brief documentation explaining the @weakify(self) @strongify(self) dance

  • Loading branch information...
1 parent 1c0f477 commit 0d388d64067bb569e5e8fadb1412be155921a162 @Machx committed Mar 28, 2013
Showing with 8 additions and 0 deletions.
  1. +4 −0 MVVM IOS Example/CDWPlayerViewModel.m
  2. +4 −0 MVVM IOS Example/CDWViewController.m
@@ -52,6 +52,8 @@ -(IBAction)resetToDefaults:(id)sender {
}
-(IBAction)uploadData:(id)sender {
+ //using with @strongify(self) this makes sure that self isn't retained in the blocks
+ //this is declared int libextobjc's EXTScope.h file
@weakify(self);
[[RACScheduler scheduler] schedule:^{
sleep(1);
@@ -60,6 +62,8 @@ -(IBAction)uploadData:(id)sender {
//upload player & points...
[[RACScheduler mainThreadScheduler] schedule:^{
+ //this creates a reference to weak self ( @weakify(self); )
+ //makes sure self isn't retained
@strongify(self);
NSString *msg = [NSString stringWithFormat:@"Updated %@ with %.0f points",self.playerName,self.points];
@@ -31,12 +31,16 @@ - (void)viewDidLoad
//Create the View Model
self.viewModel = [CDWPlayerViewModel new];
+ //using with @strongify(self) this makes sure that self isn't retained in the blocks
+ //this is declared int libextobjc's EXTScope.h file
@weakify(self);
//Start Binding our properties
RAC(self.nameField.text) = [RACAbleWithStart(self.viewModel.playerName) distinctUntilChanged];
[[self.nameField.rac_textSignal distinctUntilChanged] subscribeNext:^(NSString *x) {
+ //this creates a reference to self that when used with @weakify(self);
+ //makes sure self isn't retained
@strongify(self);
self.viewModel.playerName = x;
}];

0 comments on commit 0d388d6

Please sign in to comment.