//
// main.m
// 4-【理解】应用:block的使用场景1
//
// Created by IOSBasic_7 on 15/10/22.
// Copyright © 2015年 itheima. All rights reserved.
//
#import <Foundation/Foundation.h>
//形参是block类型的
//void (^workBlock)();
//workBlock作为函数的形参
void work(void (^workBlock)()){
NSLog(@"-----------------\n起床");
NSLog(@"刷牙");
NSLog(@"去车站");
NSLog(@"坐车");
workBlock();
NSLog(@"去车站");
NSLog(@"坐车回家");
NSLog(@"吃饭");
NSLog(@"睡觉");
}
void workDay(int n){
switch (n) {
case 1:
work(^{NSLog(@"了解项目");});
break;
case 2:
work(^{NSLog(@"分析项目");});
break;
case 3:
work(^{NSLog(@"写代码");});
break;
case 4:
work(^{NSLog(@"调试项目");});
break;
case 5:
work(^{NSLog(@"走人");});
break;
default:
break;
}
}
typedef void (^myBlockType)();
void (^block1)();
void (^block2)();
myBlockType block3;
int main(int argc, const char * argv[]) {
@autoreleasepool {
// day1();
// day2();
// day3();
// day4();
// day5();
for(int i=1;i<=5;i++){
workDay(i);
}
}
return 0;
}
//
// Person.h
// OC9-block和协议
//
// Created by beijing_ios_13 on 16/3/17.
// Copyright © 2016年 itheima. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef void (^MyInt)();
@interface Person : NSObject
//void (^)()
// myBlock
- (MyInt)test:(MyInt)myBlock;
@end
//
// Person.m
// OC9-block和协议
//
// Created by beijing_ios_13 on 16/3/17.
// Copyright © 2016年 itheima. All rights reserved.
//
#import "Person.h"
@implementation Person
@end |
|