EXC_BAD_INSTRUCTION when synthesizing @property (weak) IBOutlet NSWindow *window?

Conceptually, 'weak' is the correct qualifier for a top-level IBOutlet on OS X (iOS is another story). However, to create a proper weak reference that zeroes on deallocation requires cooperation from the Objective C runtime. Classes that override retain or release break this support and so you can't create a weak reference to them.

UIWindow is one such class That's why the template uses 'assign'. Perhaps it should really use the synonym 'unsafe_unretained' if ARC is enabled. In either case you have a simple weak reference that is not zeroed.

Conceptually, 'weak' is the correct qualifier for a top-level IBOutlet on OS X (iOS is another story). However, to create a proper weak reference that zeroes on deallocation requires cooperation from the Objective C runtime. Classes that override retain or release break this support and so you can't create a weak reference to them.

UIWindow is one such class. That's why the template uses 'assign'. Perhaps it should really use the synonym 'unsafe_unretained' if ARC is enabled.In either case you have a simple weak reference that is not zeroed.

Not to question your expertise, but citation needed :-). If for no other reason, then just to further my understanding of the topic. – JK Laiho Oct 26 at 17:20 3 clang.llvm.org/docs/AutomaticReferenceCo... I'm using 'synonym' in the sense that both imply __unsafe_unretained when used in a property declaration.

– Robin Summerhill Oct 26 at 17:34 Good enough for me! Thanks. – JK Laiho Oct 27 at 12:40.

Mike Ash has a very good explanation of what's going wrong here (search for "ARC's implementation"). The gist of it is that the NSWindow class specifically does not support weak referencing: apparently because it relies on overriding retain and release with its own implementations. I expect there's a few more such gotchas scattered through the legacy Cocoa classes, and these don't appear to be documented yet - instead, you find out through a runtime error.(I expect this will become a compiler warning as well at some point.).

Mike Ash's blog discusses the issue with some Cocoa classes. Look for it in the middle part of the page: Friday Q&A ARC. Look/Search for the text that starts with "ARC's implementation of zeroing weak references..." The problem is that some classes don't handle the zeroing weak references that __weak brings.

The solution is to go with what the normal ARC templates provide assign. Well, to answer the second question, even Apple's templates use assign for window when using ARC. So you may be safe for now.

But your mileage may vary in the future.

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