Strange crash with block and phantom block argument exchange?

It looks like when you call runBlock you are passing a block as the sender. I was able to run your code just fine Matt Gallagher has an article on How blocks are implemented which may help you debug your problem.

It looks like when you call runBlock you are passing a block as the sender. I was able to run your code just fine. Matt Gallagher has an article on How blocks are implemented which may help you debug your problem.

If you copy an NSStackBlock, it will return an NSMallocBlock (indicating its changed allocation location).

Joe's answer seems pretty much like it's likely right. You'll have to share the code that calls runBlock as well for someone to know what's actually happening, but given the name of the method you've provided, it probably looks something like: classAInstance runBlock:^BOOL(id sender) { // some code }; Which would actually print NSStackBlock instead (unless of course the block was copied first in which case it would be an NSMallocBlock). ClassAInstance runBlock:@" Would result in the output of: sender: NSStirng -NSString doSomething: unrecognized selector sent to instance Without your runBlock call, though there's no way to know where things have gone wrong.It's also possible that you are calling the method with the right argument, but that you have a memory allocation issue which leads to a block being allocated in the area you expect another object to exist, but this is probably less likely.

This is probably your problem: NSOperationQueue *queue = NSOperationQueue alloc init autorelease; You're creating an NSOperationQueue, then autoreleasing it, then expecting it to do work for you. If you want to do your work asynchronously in a separate thread there, use dispatch_async() with a concurrent queue instead: dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^() { NSLog(@"sender: %@", sender class); sender doSomething; }).

Found the reason. Duh, I feel stupid now. The mistake was attaching the block (as well as a second one) to my object as associated objects via: static NSString * const FirstBlockKey; static NSString * const SecondBlockKey; objc_setAssociatedObject(self, FirstBlockKey, blockA, OBJC_ASSOCIATION_COPY); objc_setAssociatedObject(self, SecondBlockKey, blockB, OBJC_ASSOCIATION_COPY); while I should clearly have used this: objc_setAssociatedObject(self, (void *)&FirstBlockKey, block, OBJC_ASSOCIATION_COPY); FirstBlockKey and SecondBlockKey themselves are both 0x0 obviously, while their own pointers are not.

This way it simply called the wrong block (as they both were assigned to the same `0x0' key). The blocks had different return and argument types, which seem to have caused the strange exchange of passed block arguments. Working fine n Joe, Ryan & wbyoung, thanks for your efforts guys!

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions