iOS Block与Delegate的用法,各自优缺点及使用场景

问题:

你是否有想过在UITableViewCell上把UIButton点击事件回调到UIViewController?你是否有想过在封装Alamofire或者AFNetWorking的时候回调网络数据?

概念:

Block官方解释:

Block objects are a C-level syntactic and runtime feature. They are similar to standard C functions, but in addition to executable code they may also contain variable bindings to automatic (stack) or managed (heap) memory. A block can therefore maintain a set of state (data) that it can use to impact behavior when executed.

You can use blocks to compose function expressions that can be passed to API, optionally stored, and used by multiple threads. Blocks are particularly useful as a callback because the block carries both the code to be executed on callback and the data needed during that execution.

翻译过来:

Block是C语言语法和运行时功能。它们类似于标准C函数,但除了可执行代码之外,它们还可能包含对内存变量的绑定。因此,Block可以维护一组状态(数据),它可以用于在执行时影响行为。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值