Created
May 14, 2012 08:48
-
-
Save juliengrimault/2692793 to your computer and use it in GitHub Desktop.
Retain cycle in MKNetworkOperation completion handler
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 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 | |
| } | |
| onError:^(NSError* error) { | |
| }]; | |
| } | |
| @end | |
| - (void)viewDidAppear:(BOOL)animated | |
| { | |
| __weak MyViewController* weakSelf = self; | |
| self.operation = [[Engine sharedEngine] someOperation:^(NSArray* images) | |
| { | |
| weakSelf.flickrImages = images; | |
| [weakSelf.tableView reloadData]; | |
| } | |
| onError:^(NSError* error) { | |
| }]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment