Introduction(介绍)
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.
block 对象是一个C语言级别的语法和运行时特征。他们和标准的C函数类似,但是除了包含可执行代码,他们也可以包含stack(栈,系统自动管理内存)或者heap(堆,手动管理内存)中的内存的变量。一个block可以保存一关于状态(数据的)的设置,所以当执行的时候block可以使用这些设置来影响行为。
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来组合函数表达式来传递给API,随意存储,并被多个线程使用。block 经常被用作回调函数,因为block同时具有执行回调的代码和相应需要的数据。
Blocks are available in GCC and Clang as
shipped with the OS X v10.6 Xcode developer tools. You can use blocks with OS X v10.6 and later, and iOS 4.0 and later. The blocks runtime is open source and can be found in LLVM’s
compiler-rt subproject repository. Blocks have also been presented to the C standards working group as N1370:
Apple’s Extensions to C. As Objective-C and C++ are both derived from C, blocks are designed to work with all three languages (as well as Objective-C++). The syntax reflects this goal.
block在OS X 10.6 中的Xcode 开发者工具中的gcc 和clang是允许的。你可以在OS X v10.6 和 IOS 4.0 及以后版本中使用block。block运行时是开源的 你可以在LLVM’s
compiler-rt subproject repository中找到 。block也在标准C工作中有展示见:N1370:
Apple’s Extensions to C。因为objective-C和C++都是来源于C,block被设计成可以在这三种语言中运行(也可以在Objective-C++)。block的语法实现了这个目标。
You should read this document to learn what block objects are and how you can use them from C, C++, or Objective-C.
你应该读这篇文档学习block对象是什么,和你如何在C,C++,objective-c中使用block。
Organization of This Document (block文档的组织)
This document contains the following chapters:
- Getting
Started with Blocks provides a quick, practical, introduction to blocks. - Conceptual
Overview provides a conceptual introduction to blocks. - Declaring
and Creating Blocks shows you how to declare block variables and how to implement blocks. - Blocks
and Variables describes the interaction between blocks and variables, and defines the__block
storage type modifier. - Using
Blocks illustrates various usage patterns.
文档包括下列章节:
- Getting
Started with Blocks 提供里一个快速实用的block介绍 - Conceptual
Overview 提供了一个概念性的block的介绍 - Declaring
and Creating Blocks 告诉你如何定义和实现block - Blocks
and Variables 介绍了块和变量之间的内在关系,和定义_block 存储类型的修改 - Using
Blocks 介绍了块的不同的使用模式
本文原创,转载请注明出处:http://blog.csdn.net/zhenggaoxing/article/details/44302505