As far as I know, this is a known issue that only affects simulator 4.3. Version 4.2 and the preliminary version 5.0 do not seem to demonstrate this problem. However, now this is a big problem when Lion is missing, because the latest version of Xcode with the general release supports only the 4.3 simulator where this problem occurs.
The actual reason is the hooks between the Blocks and ObjC loops. The blocks themselves will work fine, but any attempt to call an Objective-C message on them will result in segfault. This is because the Blocks runtime contains a couple of uninitialized references to the corresponding ObjC classes, and on the iOS 4.3 simulator they are never initialized when the ObjC runtime is loaded (they are initialized only if ObjC is used at all) Blocks runtime does not depend from downloading Foundation). You can verify this at run time by looking at the values ββfor _NSConcreteStackBlock , _NSConcreteGlobalBlock and _NSConcreteMallocBlock in the debugger. In simulator 4.2 or on the device, these values ββwill not be zero, but on simulator 4.3 they will still be zero.
I have a potential solution that I will refer to here if necessary, but first Iβm going to try to compress some information from Apple about whether they have a fix on the release release or if they need some more information, etc.
UPDATE: SOLVING THE PROBLEM
I have torn a lot, and this ultimately boils down to the following: don't use weak coupling with libSystem.dylib using -weak_library . Instead, you should either not use the weak libSystem link at all (I had to support iOS 3.1.x because the Blocks code code generated by the compiler in some conditional code dependent on iOS4 caused a link error during startup, i.e. a bad crash), or you should use -weak lSystem instead, which the Simulator understands better.
When you work in iOS Simulator, you can see the loaded libraries (in Xcode: "Product-> Debug-> Shared Libraries ..."), and if you look for "Blocks", you will see two elements: libsystem_blocks.dylib and libsystem_sim_blocks.dylib . The latter is the one associated with CoreFoundation, which initializes ObjC runtime gluing for the Blocks runtime. However, since you loosely libSystem library as a whole, the characters that are usually overridden by the Simulator version (since it is loaded later by libSystem) are actually overwritten at run time from the first library that implements them. This means that you will find system versions of _NSConcreteGlobalBlock and friends who have not been initialized with the custom version of ObjC for Simulator.
For (a lot!) More information about the problem, and to see how I track it, look at the thread I made on the Apple developer forums .
Jim dovey
source share