Working with Blocks(官方描述)
an Objective-C class defines an object that combines data with related behavior. sometimes, it makes sense just to represent a single task or unit of behavior, rather than a collection of methods.
Blocks are a language-level feature added to C, Objective-C and C++, which allow you to create distinct segments of code that can be passed around to methods or functions as if they were values. Blocks are Objective-C objects, which means they can be added to collections like NSArray or NSDictionary. They also have the ability to capture values from the enclosing scope, making them similar to closures lambdas in other programming languages.
this chapter explains the syntax to declare and refer to blocks, and shows how to use blocks to simplify common tasks such as collection enumeration. For further information, see Blocks Programming Topics.
Objective-C类定义了一个将数据与相关行为相结合的对象。有时候,只表示单个任务或行为单元而不是方法集合是有意义的。
块是添加到C、Objective-C和c++中的语言级特性,它允许您创建不同的代码段,这些代码段可以像传递值一样传递给方法或函数。block是Objective-C对象,这意味着它们可以添加到像NSArray或NSDictionary这样的集合中。它们还能够从封闭范围捕获值,使其类似于其他编程语言中的闭包lambdas。
本章将解释声明和引用块的语法,并展示如何使用块来简化常见任务,例如集合枚举。有关更多信息,请参见模块编程主题。
-----本结果来自有道神经网络翻译