Skip to content

Instantly share code, notes, and snippets.

@bricklife
Last active December 17, 2015 14:29
Show Gist options
  • Save bricklife/5624811 to your computer and use it in GitHub Desktop.
Save bricklife/5624811 to your computer and use it in GitHub Desktop.
ARC + Blocks examination
# MyObject.h
@interface MyObject : NSObject
@property (nonatomic, copy) void (^block)();
@property (nonatomic, copy) NSString *str;
- (void)performBlock;
@end
# MyObject.m
@implementation MyObject
- (void)performBlock
{
if (self.block) {
self.block();
}
}
@end
# Test
MyObject *object = [[MyObject alloc] init];
object.str = @"hoge";
object.block = ^{
NSLog(@"block: str=%@", object.str);
};
[object performBlock];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment