How Do I Declare A Block in Objective-C?

As a local variable:

returnType (^blockName)(parameterTypes) = ^returnType(parameters) {...};

As a property:

@property (nonatomic, copy) returnType (^blockName)(parameterTypes);

As a method parameter:

- (void)someMethodThatTakesABlock:(returnType (^)(parameterTypes))blockName;

As an argument to a method call:

[someObject someMethodThatTakesABlock:^returnType (parameters) {...}];

As a typedef:

typedef returnType (^TypeName)(parameterTypes);
TypeName blockName = ^returnType(parameters) {...};

This site is not intended to be an exhaustive list of all possible uses of blocks.
If you find yourself needing syntax not listed here, it is likely that a typedef would make your code more readable.

Unable to access this site due to the profanity in the URL? http://goshdarnblocksyntax.com is a more work-friendly mirror.

转自:http://fuckingblocksyntax.com/

How Do I Declare A Block in Objective-C? [备忘]的更多相关文章

  1. How Do I Declare A Block in Objective-C?

    As a local variable: returnType (^blockName)(parameterTypes) = ^returnType(parameters) {...}; As a p ...

  2. 备忘:BLOCK CORRUPTION IN SYSTEM DATAFILE

    http://www.onlinedbasupport.com/2010/12/10/block-corruption-in-system-datafile/

  3. JS 实现全屏预览 F11功能

    老是不通过,没办法,只能是重新发布了,反正我就是杠上了,大大小小写过很多前端特效,当然也经常在网上copy或者修改人家的代码,我觉得也挺好的,为什么?!因为我想这样,你能怎么办,打我?少废话,直接上代 ...

  4. Objective C block背后的黑魔法

    前言 block在Objective C开发中应用非常广泛,我们知道block会捕获外部对象,也知道使用block要防止循环引用. "知其然而不知其所以然"是一件非常痛苦的事情,那 ...

  5. 堆block和栈block的区分

    0. 问题所在 下面给出一段代码: - (NSArray*) getBlockArray { int num = 916; return [[NSArray alloc] initWithObject ...

  6. Block 再学习 !

    如何优雅的使用 Block? How Do I Declare A Block in Objective-C? 阮一峰的一句话解释简洁明了:闭包就是能够读取其它函数内部变量的函数 详情:http:// ...

  7. [New learn]讲解Objective-c的block知识

    1.简介 OC的Block感觉就是C中饿函数指针,提供回调功能,但是OC中的block比C的函数指针要更加强大,甚至可以访问本地变量和修改本地变量. block在oc中是一个对象,它可以像一般的对象那 ...

  8. (译)IOS block编程指南 2 block开始

    Getting Started with Blocks(开始block) The following sections help you to get started with blocks usin ...

  9. 初识block

    我们可以把Block当做Objective-C的匿名函数.Block允许开发者在两个对象之间将任意的语句当做数据进行传递,往往这要比引用定义在别处的函数直观.另外,block的实现具有封闭性(clos ...

随机推荐

  1. [LeetCode] Network Delay Time 网络延迟时间

    There are N network nodes, labelled 1 to N. Given times, a list of travel times as directed edges ti ...

  2. python学习记录 - python3.x中如何实现print不换行

    python3.x中如何实现print不换行   大家应该知道python中print之后是默认换行的, 那如何我们不想换行,且不想讲输出内容用一个print函数输出时,就需要改变print默认换行的 ...

  3. Error:ivalue require as left operant of assignment

    Error:ivalue require as left operant of assignment 解答:该错误的意思是左操作数必须为左值,这个发生错误的原因在于赋值符号的左边不能是已确定的值,如: ...

  4. [HNOI2012]与非

    题目描述 NAND(与非)是一种二元逻辑运算,其运算结果为真当且仅当两个输入的布尔值不全为真.NAND运算的真值表如下(1表示真,0表示假): 两个非负整数的NAND是指将它们表示成二进制数,再在对应 ...

  5. Begin again

    新的一周开始. 写下这篇东西, 用来表明我还在奋斗的路上, 那么,加油咯.

  6. 2015 多校联赛 ——HDU5325(DFS)

    Crazy Bobo Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Tota ...

  7. POJ 3415 不小于k的公共子串的个数

    Common Substrings Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 9248   Accepted: 3071 ...

  8. java判断A字符串是否包含B字符串

    public static void main(String[] args) { String str="ABC_001"; if(str.indexOf("ABC&qu ...

  9. audioplayer.js插件的使用及小bug

    之前在项目里用audioplayer.js做的一个页面,改了布局样式,还有插件自身有个bug就是audio添加autoplay属性后有两个音频播放,其中一个无法控制,会一直播放,我查看了官网的demo ...

  10. linux上快速搭建宝塔面板来操作便捷功能

    关于宝塔 Linux版请确保纯净系统安装(支持CentOS.Ubuntu.Debian.Fedora.Deepin),Web端管理,QQ群及论坛技术支持一键LAMP/LNMP.创建网站FTP.数据库. ...