On 15 Feb 2012, at 12:58 PM, Matt Neuburg wrote: > * Why was I crashing until I said __block?
Without __block, the value of the variable is copied into the block (effectively as a const local variable) when the block is created. With __block, both the code inside and outside the block reference the same variable, and each can see each others' modifications (almost like a closure in languages that have that). The block is created before 'observer' is initialized (it has to be, so that it can be passed to -addOberver...), so the value of 'observer' it captures when it is created is the value of the uninitialized stack variable. It's as if you were doing this: id observer = createObserverStuff(observer); instead of this, which is kinda sorta what happens with __block variables: id observer = createObserverStuff(&observer); _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com