views:

72

answers:

2

I've been using http://code.google.com/p/plblocks/ for a while now to get blocks support in our 3.2 iPad app. It was recently pointed out to me that you can set xcode to use the 4.0 SDK, then set the OS Deployment target to 3.2.

If I do, the following code works.

void (^world)() = ^ {
    NSLog(@"Hello World");
};

NSLog(@"Hello?");

world();

However, any time I sent a message to a block I get an EXC_BAD_ACCESS. For example, if I add the following line:

void (^acopy)() = [world copy];

This is a problem, since you have to copy blocks in order for them to keep their scope around later. Any idea why blocks would work, but the messages wouldn't? Am I missing some setting or something? Am I mistaken about the need to copy?

+1  A: 

It seems you can still use Block_copy(). I don't know why PLBlocks would be able to use the Objective-C and the built-in compilers can't.

Cory Kilger
Yeah, lame, that means I can't use `@property (copy)` :( Oh well. I think we'll just stick with Plausible Blocks for now then.
Sean Clark Hess
Probably a good idea.
Cory Kilger
A: 

Here's an intro article:

http://developer.apple.com/mac/articles/cocoa/introblocksgcd.html

It says:

Importantly, block objects are laid out in such a way that they are also Objective-C objects if that runtime is present.

I can't really see how you could be developing an iPad app without the Objective-C runtime present. As a sanity check you could make sure the C version (Block_copy()) works.

Frank Schmitt
The Objective-C runtime is definitely present :) Block_copy() works.
Sean Clark Hess