Skip to content

Instantly share code, notes, and snippets.

@juliengrimault
Created May 14, 2012 08:48
Show Gist options
  • Select an option

  • Save juliengrimault/2692793 to your computer and use it in GitHub Desktop.

Select an option

Save juliengrimault/2692793 to your computer and use it in GitHub Desktop.
Retain cycle in MKNetworkOperation completion handler
@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