- #import <Foundation/Foundation.h>
- void work(void(^workBlock)()){
- NSLog(@"起床");
- NSLog(@"刷牙");
- NSLog(@"去车站");
- NSLog(@"坐车");
- workBlock();
- NSLog(@"去车站");
- NSLog(@"坐车回家");
- NSLog(@"吃饭");
- NSLog(@"睡觉");
- }
- typedef void(^Working)();
- Working workDay(int d){
- Working w;
- switch (d) {
- case 1:
- w=^(){
- work(^(){
- NSLog(@"了解项目");
- });
- };
- break;
- case 2:
- w=^(){
- work(^(){
- NSLog(@"分析项目");
- });
- };
- break;
- case 3:
- w=^(){
- work(^(){
- NSLog(@"写代码");
- });
- };
- break;
- case 4:
- w=^(){
- work(^(){
- NSLog(@"调试项目");
- });
- };
- break;
- case 5:
- w=^(){
- work(^(){
- NSLog(@"离职");
- });
- };
- break;
- default:
- break;
- }
- return w;
- }
- int main(int argc, const char * argv[]) {
- @autoreleasepool {
- Working wo=workDay(3);
- wo();
- }
- return 0;
- }
复制代码 |
|