Skip to content

Instantly share code, notes, and snippets.

@kylesluder
Created November 8, 2010 17:26
Show Gist options
  • Save kylesluder/667967 to your computer and use it in GitHub Desktop.
Save kylesluder/667967 to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
@protocol Foo
@property (readonly, nonatomic) int blah;
@end
typedef void (^bk)(void);
@interface Foo : NSObject<Foo>
{ int v; }
- (bk)makeBlock:(id<Foo>)otherFoo;
@end
@implementation Foo
- (int)blah {
NSLog(@"Blah");
return 1;
}
- (bk)makeBlock:(id<Foo>)otherFoo {
return [^{ self->v = otherFoo.blah; } copy];
}
@end
bk mkBlock(Foo* f) {
return [^{ [f blah]; } copy];
}
int main(int argc, char **argv) {
NSAutoreleasePool *pool __attribute__((unused)) = [NSAutoreleasePool new];
Foo *f = [Foo new], *g = [Foo new];
bk b = [f makeBlock:g];
b();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment