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 160. Intersection of Two Linked Lists 求两个链表的起始重复位置 --------- java

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  2. Swiper说明及API手册说明

    最近使用Swipe.js,发现中文的资料很少,试着翻译了一下.能力有限,翻译难免错漏,欢迎指出,多谢! 翻译自:http://www.idangero.us/sliders/swiper/api.ph ...

  3. Linux应用程序的地址布局

    转载自:http://blog.csdn.net/embedded_hunter http://www.360doc.com/content/12/0405/00/1671317_200882538. ...

  4. 论文阅读之:PRIORITIZED EXPERIENCE REPLAY

    PRIORITIZED EXPERIENCE REPLAY ICLR 2016 经验回放使得 online reinforcement learning agent 能够记住并且回放过去的经验.在先前 ...

  5. What are the main disadvantages of Java Server Faces 2.0?

    http://stackoverflow.com/questions/3623911/what-are-the-main-disadvantages-of-java-server-faces-2-0/ ...

  6. dede数据库文件导入失败的可能原因是数据表前缀不同,这里的失败指的是mysql添加了数据,但后台不显示

    利用dede提供的数据备份还原功能,还原数据,出现失败的可能原因是数据表前缀不同,改过来就可以了

  7. SQL server 2008 Express Edition实现自动备份和自动删除备份

    1.查看SQL 版本: select @@VERSION --可以看到 Express Edition 精简免费版 Microsoft SQL Server 2008 R2 (SP2) - 10.50 ...

  8. nmap与ntop

    http://blog.csdn.net/aspirationflow/article/details/7694274

  9. 【转】Asp.net中时间格式化的6种方法详细总结

    1. 数据控件绑定时格式化日期方法: 代码如下: <asp:BoundColumn DataField="AddTime" HeaderText="添加时间&quo ...

  10. ASP.NET MVC中的错误-友好的处理方法

    转自:http://blog.csdn.net/lizhao1226/article/details/6367400 “/”应用程序中的服务器错误. 无法找到资源. 说明: HTTP 404.您正在查 ...