2019-06-28

How Do I Declare A Block in Objective-C?

As alocal variable:


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

As aproperty:


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

As amethod parameter:


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

As anargument to a method call:


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

As aparameter to a C function:

void SomeFunctionThatTakesABlock(returnType (^blockName)(parameterTypes));

As atypedef:

typedef returnType (^TypeName)(parameterTypes);

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

转载来自http://fuckingblocksyntax.com/

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom阅读 2,719评论 0 3
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,424评论 0 10
  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 9,503评论 0 13
  • 15年的农历8月15,我跟高林一起熬了一宿的火车第二天早上到了济南一起约晓雨玩,还定了到青岛和回程的票。 那年,我...
    我是丹玉呀阅读 257评论 0 3
  • 安装所需环境 Nginx 是 C语言 开发,建议在 Linux 上运行,当然,也可以安装 Windows 版本,本...
    神秘者007阅读 230评论 0 0