类型之间而不是变量之间的插入符,用括号括起来
我在浏览 Apple 的文档时看到了类似 (void (^)(void))
的内容。有人能解释一下这句话的意思吗? ^
是异或,对吗? void XOR void
对我来说没有多大意义?
还有类似 (void (^)(BOOL finish))
I was going through Apple's documentation and I saw something like this (void (^)(void))
. Can somebody explain what this statement means? ^
is XOR, right? void XOR void
doesn't makes much sense to me?
There was also something like (void (^)(BOOL finished))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这些块将匿名函数和函数对象添加到 Objective-C。请参阅介绍块和大中央调度:
声明块变量:
将块对象分配给它:
调用它:
接受块作为参数:
将该方法与内联块一起使用:
These are blocks which add anonymous functions and function objects to Objective-C. See e.g. Introducing Blocks and Grand Central Dispatch :
Declaring a block variable:
Assigning a block object to it:
Invoking it:
Accepting a block as an argument:
Using that method with an inline block:
这是一个块,Apple 特定的 C 扩展,类似于函数指针,或其他语言中的函数对象。
(void (^)(void))
看起来像是对不带参数且不返回任何内容的块类型的类型转换。类似地,(void (^)(BOOL finish))
看起来像是另一种类型转换,是一个带有一个布尔参数且不返回任何内容的块。That's a block, an Apple-specific extension to C, similar to function pointers, or function objects in other languages.
(void (^)(void))
looks like a typecast to the type of a block that takes no parameters and returns nothing. Similarly,(void (^)(BOOL finished))
looks like another typecast, to a block with one boolean parameter and returning nothing.