Skip to content

Instantly share code, notes, and snippets.

Last active December 31, 2015 00:59
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Does this no longer have the cycle?
#import <Foundation/Foundation.h>
@interface A : NSObject
- (void)doThingWithObject:(id)o completion:(void(^)(void))completionHandler;
@implementation A
- (void)doThingWithObject:(id)o completion:(void(^)(void))completionHandler
NSLog(@"object: %@", o);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
if(completionHandler) completionHandler();
int main(int argc, char *argv[]) {
@autoreleasepool {
A *a = [A new];
NSArray *someThings = @[@0, @1, @2];
NSEnumerator *e = [someThings objectEnumerator];
void(^ completionHandler)(void);
__unsafe_unretained __block void(^handler)(void);
completionHandler = ^{
id o = [e nextObject];
if (o) {
[a doThingWithObject:o completion:handler];
completionHandler = [completionHandler copy];
handler = completionHandler;
Copy link

wolffan commented Dec 11, 2013

When the variable it's not a block I use __weak. But I get another warning with this

Bot with a block I'm clueless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment