开发者

EXC_BAD_ACCESS when sending messages to blocks on 4.0 -> 3.2

开发者 https://www.devze.com 2023-01-03 21:32 出处:网络
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

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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消