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 the following is not what it's looking for...
void SomeHandler( void )
{
}
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
Block Objects
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:
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.
Syntax
A block variable looks like a function pointer, except with a caret (‘^’) instead of an asterisk (‘*’).
void (^my_block)(void);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With