关于oc中出现的typedef的用法/定义函数指针
typedef int (^calculateBlock)(int a,int b);
这里面typedef的作用只是给 calculateBlock取了一个 别名,说明以后可以直接使用。
calculateBlock类似于*所以可以有类似的用法,以后可以直接使用calculateBlock来定义方法。例:
- (int)calculateWithNumber1:(int)number1 andNumber:(int)number2 andCalculate:(calculateBlock)calculate;
直接使用calculateBlock来定义作为方法的参数。做到的调用为:
- (int)calculateWithNumber1:(int)number1 andNumber2:(int)number2 andCalculate:(calculateBlock)calculate
{
//经常变化的功能,在设计当中叫做封装变化
return calculate(number1,number2);
}
在main中代码为:
int (^sumBlock)(int a, int b) = ^int (int a, int b) {
int result = (a * b);
x = result;
return result;
};
调用自己定义的方法:
int sum =[cal calculateWithNumber1:10 andNumber:20 andCalculate:sumBlock];
在不知道使用什么样的方式计算时可以使用传入block。来假设。
关于oc中出现的typedef的用法/定义函数指针的更多相关文章
- OC中协议的概念以及用法
OC中协议的概念以及用法,协议也是OC中的一个重点,Foundation框架以及我们后面在写代码都会用到. OC中的协议就是相当于Java中的接口(抽象类),只不过OC中的名字更形象点,因为我们在学习 ...
- c语言定义函数指针和typedef简写
二种方法来定义函数指针 #include<stdio.h> #include<stdlib.h> #include<Windows.h> int add(int a ...
- objective-c中的@selector()和 c /c++的函数指针
先看tomcat里用到的代码: //然后开始动画 //把图片放到animationImages,接受数组参数 self.tom.animationImages = arrayImage; //设置时间 ...
- 用typedef定义函数指针的问题
在学习windows API的时候,遇到下面这段代码 以前见过的typedef的用法都是给一个数据类型取一个别名 typedef oldTypeName newTypeName 这种给数据类型 ...
- 再谈typedef(重点为函数指针)
有种很方便的写法. typedef int *p: p pointer: 这时直接把pointer带入原式中,取代p然后去掉typedef,得到的结果就是int * pointer: 哈哈,这样直接替 ...
- 【AT91SAM3S】SAM3S-EK Demo工程中,LCD驱动程序的加载(函数指针结构体)
为了调试LCD,在英倍特的板子上烧Atmel的sam3s-ek_demo_1.4_source示例代码.LCD显示正常了,却找不到LCD的驱动究竟在哪. 花了好久,追踪到了这个执行过程. 进入main ...
- OC中extern,static,const的用法
1.const的作用: const仅仅用来修饰右边的变量(基本数据变量p,指针变量*p). 例如 NSString *const SIAlertViewWillDismissNotification; ...
- C 中typedef 函数指针的使用
类型定义的语法可以归结为一句话:只要在变量定义前面加上typedef,就成了类型定义.这儿的原本应该是变量的东西,就成为了类型. int integer; //整型变量int *pointer ...
- C中typedef 函数指针的使用
类型定义的语法可以归结为一句话:只要在变量定义前面加上typedef,就成了类型定义.这儿的原本应该是变量的东西,就成为了类型. int integer; //整型变量int *pointer ...
随机推荐
- c#---部分;把数组或者结构体存入集合里,然后再从集合中取出之后,输出;foreach既可以用到提取数组重点额数据,也可以提取集合中的数据(前提是集合中的元素是相同数据类型)
1.输入班级人数,统计每个人的姓名,性别,年龄:集合与数组 //Console.Write("请输入班级人数:"); //int a = int.Parse(Console.Rea ...
- 工作中遇到的问题--eclipse没有方法提示
一.eclipse自身配置问题步骤:1. 打开Eclipse ,然后“window”→“Preferences”2. 选择“java”,展开,“Editor”,选择“Content Assist”.3 ...
- stl中双向队列用法
双向队列的操作如下: d[i]:返回d中下标为I的元素的引用. d.front():返回的一个元素的引用. d.back():返回最后一个元素的引用. d.pop_back():删除尾部的元素.不返回 ...
- JS的prototype的共享机制分析
function Super(){ } Super.prototype.aaa=[1,2,3]; Super.prototype.bbb=1; function Sub(){ Super.call(t ...
- [译] AlphaGo 的确是一个大事件
[译] AlphaGo 的确是一个大事件 转自:http://www.jianshu.com/p/157a15de47df 字数3797 阅读696 评论0 喜欢4 作者:Michael Nielse ...
- MAVEN build ,GOAL plugin ,execution
http://www.avajava.com/tutorials/lessons/what-are-the-phases-of-the-maven-clean-lifecycle.html https ...
- Python元组的简单介绍
1.实际上元组是跟列表非常相近的另一种容器类型.元组和列表看上去的不同的一点是元组用圆括号而列表用方括号.而在功能上,元组是一种不可变的类型.正是因为这个原因,元组可以做一些列表不可以做的事情,比如用 ...
- mysql 1449 : The user specified as a definer ('root'@'%') does not exist ,mysql 赋给用户权限 grant all privileges on
mysql 1449 : The user specified as a definer ('root'@'%') does not exist 解决方法 遇到了 SQLException: acce ...
- mfs-用户
http://blog.csdn.net/liuyunfengheda/article/details/5260278 MFS总结 http://bbs.chinaunix.net/thread-16 ...
- linux服务之openfiler
架构:b/s 服务器端:封装好的linux系统 客户端:浏览器 相关包:封装好的linux系统 Openfiler imports user and group information from ce ...