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的用法/定义函数指针的更多相关文章

  1. OC中协议的概念以及用法

    OC中协议的概念以及用法,协议也是OC中的一个重点,Foundation框架以及我们后面在写代码都会用到. OC中的协议就是相当于Java中的接口(抽象类),只不过OC中的名字更形象点,因为我们在学习 ...

  2. c语言定义函数指针和typedef简写

    二种方法来定义函数指针 #include<stdio.h> #include<stdlib.h> #include<Windows.h> int add(int a ...

  3. objective-c中的@selector()和 c /c++的函数指针

    先看tomcat里用到的代码: //然后开始动画 //把图片放到animationImages,接受数组参数 self.tom.animationImages = arrayImage; //设置时间 ...

  4. 用typedef定义函数指针的问题

    在学习windows API的时候,遇到下面这段代码   以前见过的typedef的用法都是给一个数据类型取一个别名 typedef oldTypeName newTypeName   这种给数据类型 ...

  5. 再谈typedef(重点为函数指针)

    有种很方便的写法. typedef int *p: p pointer: 这时直接把pointer带入原式中,取代p然后去掉typedef,得到的结果就是int * pointer: 哈哈,这样直接替 ...

  6. 【AT91SAM3S】SAM3S-EK Demo工程中,LCD驱动程序的加载(函数指针结构体)

    为了调试LCD,在英倍特的板子上烧Atmel的sam3s-ek_demo_1.4_source示例代码.LCD显示正常了,却找不到LCD的驱动究竟在哪. 花了好久,追踪到了这个执行过程. 进入main ...

  7. OC中extern,static,const的用法

    1.const的作用: const仅仅用来修饰右边的变量(基本数据变量p,指针变量*p). 例如 NSString *const SIAlertViewWillDismissNotification; ...

  8. C 中typedef 函数指针的使用

    类型定义的语法可以归结为一句话:只要在变量定义前面加上typedef,就成了类型定义.这儿的原本应该是变量的东西,就成为了类型. int integer;     //整型变量int *pointer ...

  9. C中typedef 函数指针的使用

    类型定义的语法可以归结为一句话:只要在变量定义前面加上typedef,就成了类型定义.这儿的原本应该是变量的东西,就成为了类型. int integer;     //整型变量int *pointer ...

随机推荐

  1. leetcode 149. Max Points on a Line --------- java

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...

  2. JS数组随机排序

    var arr=[1,2,3,4,5]; arr.sort(function(a,b){ var v=Math.random()>0.5?1:-1; console.log(a,b,v); re ...

  3. 【POJ3904】【P1202】水晶密码

    说是莫比乌斯反演,其实只是玩儿玩儿内个miu函数而已…… 原题: wty  打算攻击 applepi  的用来存放机密数据的水晶系统. applepi 早有察觉,于是布置了一个密码系统来防备 wty ...

  4. 系统镜像以及微PE工具箱

    微PE地址:http://www.wepe.com.cn/download.html MSDN镜像下载地址:http://msdn.itellyou.cn/ 小白也能轻松装系统(win10 64位) ...

  5. memory dump and CLR Inside Out

    MSDN Magazine: CLR Inside Out https://msdn.microsoft.com/en-us/magazine/cc501040.aspx CLR Inside Out ...

  6. luke 操作记录

    精确查询(不需要切分词):得使用KeywordAnalyzer而不是StandardAnalyzer,原因如下: StandardAnalyzer:

  7. ASP.NET MVC报错: Multiple types were found that match the controller named

    当使用ASP.NET MVC的Area功能时,出现了这样的错误: Multiple types were found that match the controller named 'Home'. T ...

  8. 【转】Php+ajax+jsonp解决ajax跨域问题

    首先:jsonp是json用来跨域的一个东西. 原理是通过script标签的跨域特性来绕过同源策略. 发送端: $.ajax({ type : "post", url : &quo ...

  9. svn安装

    方法三.无法连接网络的情况(link链接) 1.从官网下载 Site-1.6.5.zip 2.解压Site-1.6.5.zip至${eclipse}PluginsSubclipse-1.6.5.zip ...

  10. 服务器安全狗,支持Linux/windows

    安全狗: www.safedog.cn 防DDOS  sql注入检测