Using Objective-C blocks with old compiler

Posted by H2CO3 on Stack Overflow See other posts from Stack Overflow or by H2CO3
Published on 2011-11-12T10:39:40Z Indexed on 2011/11/14 1:51 UTC
Read the original article Hit count: 589

I'm using the opensource iPhone toolchain on Linux for developing for jailbroken iPhones. I'd like to take advantage of the new (4.0, 5.0) iOS SDK features, but I can't as my old build of GCC doesn't understand the ^ block syntax. I noticed that blocks are just of type id (struct objc_object *). I know this from two resources: first, class-dump reports them as id, second, Apple docs clarify that "blocks can be retained". My quiestion is, how can I take advantage of blocks using this knowledge? I thought of something like:

// this is in SDK 4.x/5.x
- (void) doSomethingWithBlock:((int)(^block)(int));
// and I modify it like:
- (void) doSomethingWithBlock(id)block;

the question is: HOW TO ACTUALLY CALL IT? How do I create blocks? I can, of course, create function pointers (IMPs in particular), but how to achieve the object-like memory layout?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c