问题:
你是否有想过在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可以维护一组状态(数据),它可以用于在执行时影响行为。