main.m
Button.h
Button.m
//
// main.m
// Block1
//
// Created by Rayln Guan on 8/30/13.
// Copyright (c) 2013 Rayln Guan. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Button.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
Button *btn = [[Button alloc] init];
btn.block = ^(Button *btn){
NSLog(@"Button 被点击了");
};
[btn click];
[btn release];
}
return 0;
}
Button.h
//
// Button.h
// Block1
//
// Created by Rayln Guan on 8/30/13.
// Copyright (c) 2013 Rayln Guan. All rights reserved.
//
#import <Foundation/Foundation.h>
@class Button;
typedef void (^ButtonBlock) (Button *);
@interface Button : NSObject
@property ButtonBlock block;
- (void) click;
@end
Button.m
//
// Button.m
// Block1
//
// Created by Rayln Guan on 8/30/13.
// Copyright (c) 2013 Rayln Guan. All rights reserved.
//
#import "Button.h"
@implementation Button
- (void)click{
_block(self);
}
@end