oc_study26
来源:互联网 发布:如何申请淘宝介入 编辑:程序博客网 时间:2024/06/05 02:50
main.h
//// main.m// oc_s26//// Created by sekey on 15/3/19.// Copyright (c) 2015年 showerli1991. All rights reserved.//#import <Foundation/Foundation.h>#import "Person.h"//int sum(int a, int b)//{// return a + b;//}//typedef int (^MyBlock) (int, int);int main(void){ Person * p = [[Person alloc] init]; [p test]; // MyBlock minusBlock = ^(int a, int b)// {// return a - b;// };// // MyBlock sunBlock = ^(int a, int b)// {// return a + b;// };// // MyBlock multiplyBlock = ^(int a, int b)// {// return a * b;// };// // NSLog(@"minusBlock = %i, sunBlock = %i, multiplyBlock = %i", minusBlock(10, 5), sunBlock(5, 5), multiplyBlock(2, 6));// // // int (*p)(int, int) = sum;// int d = p(11, 13); // void (^lineblock)(int) = ^(int n)// {// for (int i=0; i<n; i++)// {// NSLog(@"-------");// }// };// // lineblock(3); // // int (^sumblock)(int, int) = ^(int a, int b)// {// return a + b;// };// // int c = sumblock(10, 11);// // NSLog(@"c = %i", c);// return 0;}void test(void){ //block //block sign: ^ /* block和函数类似 1.可以保存代码 2.有返回值 3.有形参 */ //定义block变量 void (^myblock)(void) = ^{ NSLog(@"block defined"); }; //利用block变量调用bloack代码 myblock(); return;}
Person.h
//// Person.h// oc_s26//// Created by sekey on 15/3/19.// Copyright (c) 2015年 showerli1991. All rights reserved.//#import <Foundation/Foundation.h>#import "MyProtocol.h"#import "MyProtocol2.h"@interface Person : NSObject <MyProtocol, MyProtocol2>@end
Person.m
//// Person.m// oc_s26//// Created by sekey on 15/3/19.// Copyright (c) 2015年 showerli1991. All rights reserved.//#import "Person.h"@implementation Person- (void)test{ NSLog(@"haha");}- (void)test2{ NSLog(@"test2");}@end
MyProtocol.h
//// MyProtocol.h// oc_s26//// Created by sekey on 15/3/19.// Copyright (c) 2015年 showerli1991. All rights reserved.//#import <Foundation/Foundation.h>@protocol MyProtocol <NSObject>- (void)test;- (void)test2;- (void)description;@end
MyProtocol2.h
#import <Foundation/Foundation.h>@protocol MyProtocol2 <NSObject>@end
0 0
- oc_study26
- java.lang.IllegalStateException at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFa
- MongoDB 安全介绍
- GIS silverlight随堂作业2街景图卫星图切换
- TCP协议中的三次握手和四次挥手(图解)
- 第三周:程序阅读(3)
- oc_study26
- MongoDB 提高安全技巧
- 常用数据库基本数据类型
- POJ 1556 The Doors(计算几何+最短路)
- 依萍母女到底多有钱答案在这里
- dsp与arm
- 学习笔记_03_HTML5
- HDU 3065 病毒侵袭持续中(AC自动机)
- 学习思想