Created
May 14, 2012 08:48
-
-
Save juliengrimault/2692793 to your computer and use it in GitHub Desktop.
Revisions
-
Julien Grimault revised this gist
May 14, 2012 . 1 changed file with 20 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -10,12 +10,20 @@ @interface MyViewController : UITableViewController @end @implementation MyViewController @synthesize operation = operation; - (void)setOperation:(MKNetworkOperation*)operation { if (_operation == operation) return; [_operation cancel]; _operation = operation; } - (void)viewDidAppear:(BOOL)animated { self.operation = [[Engine sharedEngine] someOperation:^(NSArray* images) { self.flickrImages = images; [self.tableView reloadData];//retain cycle here } @@ -25,6 +33,17 @@ - (void)viewDidAppear:(BOOL)animated @end My VC has a strong reference to the operation that in turn copies the completion block that retains `self`, this creates a retain cycle I believe. A way to break it would be set the operation to nil in `viewDidDisapear:` - (void)viewDidDisappear:(BOOL)animated { self.operation = nil; } or to create a weak reference of self - (void)viewDidAppear:(BOOL)animated { __weak MyViewController* weakSelf = self; -
Julien Grimault revised this gist
May 14, 2012 . 1 changed file with 3 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ @interface Engine + (id)sharedEngine; - (MKNetworkOperation*)someOperation:(CompletionBlock)block onError:(ErrorBlock)errorBlock; @@ -28,12 +27,11 @@ - (void)viewDidAppear:(BOOL)animated - (void)viewDidAppear:(BOOL)animated { __weak MyViewController* weakSelf = self; self.operation = [[Engine sharedEngine] someOperation:^(NSArray* images) { weakSelf.flickrImages = images; [weakSelf.tableView reloadData]; } onError:^(NSError* error) { -
Julien Grimault revised this gist
May 14, 2012 . 1 changed file with 16 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,20 @@ @interface Engine + (id)sharedEngine; - (MKNetworkOperation*)someOperation:(CompletionBlock)block onError:(ErrorBlock)errorBlock; @end @interface MyViewController : UITableViewController @property (nonatomic, strong) MKNetworkOperation* operation; @end @implementation MyViewController - (void)viewDidAppear:(BOOL)animated { self.operation = [[Engine sharedEngine] someOperation:^(NSArray* images) { self.flickrImages = images; //retain cycle here [self.tableView reloadData];//retain cycle here @@ -11,6 +24,7 @@ - (void)viewDidAppear:(BOOL)animated }]; } @end - (void)viewDidAppear:(BOOL)animated { -
Julien Grimault revised this gist
May 14, 2012 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,6 @@ - (void)viewDidAppear:(BOOL)animated { self.operation = [ApplicationDelegate.flickrEngine imagesForTag:@"Singapore" onCompletion:^(NSMutableArray* images) { self.flickrImages = images; //retain cycle here @@ -16,7 +15,7 @@ - (void)viewDidAppear:(BOOL)animated - (void)viewDidAppear:(BOOL)animated { __weak FlickrTableViewController weakSelf = self; //to prevent retain cycle self.operation = [ApplicationDelegate.flickrEngine imagesForTag:@"Singapore" onCompletion:^(NSMutableArray* images) { weakSelf.flickrImages = images; -
Julien Grimault created this gist
May 14, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ - (void)viewDidAppear:(BOOL)animated { [ApplicationDelegate.flickrEngine imagesForTag:@"Singapore" onCompletion:^(NSMutableArray* images) { self.flickrImages = images; //retain cycle here [self.tableView reloadData];//retain cycle here } onError:^(NSError* error) { }]; } - (void)viewDidAppear:(BOOL)animated { __weak FlickrTableViewController weakSelf = self; //to prevent retain cycle [ApplicationDelegate.flickrEngine imagesForTag:@"Singapore" onCompletion:^(NSMutableArray* images) { weakSelf.flickrImages = images; [weakSelf.tableView reloadData]; } onError:^(NSError* error) { }]; }