插入式^语法(两侧均为空)是什么意思? [英] What does this caret ^ syntax, with void on either side mean?

查看:81
本文介绍了插入式^语法(两侧均为空)是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iPhone SDK 4.0中,UIApplication具有新方法setKeepAliveTimeout:,该方法需要第二个类型为void(^)(void)的参数.

In iPhone SDK 4.0, UIApplication has a new method, setKeepAliveTimeout: that requires a second parameter of type void(^)(void).

-(BOOL)setKeepAliveTimeout:(NSTimeInterval)timeout handler:(void(^)(void))keepAliveHandler

第二个参数的语法到底是什么意思,我将如何声明可以传递给它的函数/处理程序?

What exactly does the syntax of the second parameter mean, and how would I declare a function/handler that I can pass into it?

FWIW,以下不是它要找的东西...

FWIW the following is not what it's looking for...

void SomeHandler( void )
{
}

推荐答案

这是块",Apple在Snow Leopard中为C添加了一项新功能.更多信息,请访问:

It is a "block", a new feature Apple added to C in Snow Leopard. Lots more info available at:

https://developer.apple .com/library/mac/documentation/Cocoa/Conceptual/Blocks/Articles/00_Introduction.html

块对象

块对象(非正式地称为块")是C以及Objective-C和C ++的扩展,使程序员可以轻松地定义独立的工作单元.块与传统函数指针类似,但功能比传统函数指针强大得多.关键区别在于:

Block objects (informally, "blocks") are an extension to C, as well as Objective-C and C++, that make it easy for programmers to define self-contained units of work. Blocks are similar to — but far more powerful than — traditional function pointers. The key differences are:

块可以内联定义为匿名函数". 块捕获局部变量的只读副本,类似于其他语言中的"closures" 这种功能在动态类型的解释语言中很常见,但是以前从未广泛用于C程序员.苹果公司已根据MIT许可以开源形式发布了块语言规范和我们的实现,并向GCC 4.2和clang添加了块支持,并将其提交作为下一版C编程语言的一部分进行审议.

Blocks can be defined inline, as "anonymous functions." Blocks capture read-only copies of local variables, similar to "closures" in other languages This is kind of functionality is common in dynamically-typed interpreted languages, but has never before been widely available to C programmers. Apple has published both the Blocks Languages Specification and our implementation as open source under the MIT license, added blocks support to GCC 4.2 and clang, and has submitted it for consideration as part of the next version of the C programming language.

语法

块变量看起来像函数指针,只是带有脱字符号('^')而不是星号('*').

A block variable looks like a function pointer, except with a caret (‘^’) instead of an asterisk (‘*’).

void (^my_block)(void);

这篇关于插入式^语法(两侧均为空)是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆