Cocoa [NSView viewDidLoad] debugging

I’ve noticed that if you call a selector on an object that doesn’t support that selector (e.g. viewDidLoad on a NSView) during [NSViewController viewDidLoad] the exception causes the view or window to silently fail to draw and you get a window with no content. This can be frustrating to track down, and certainly quite mystifying the first time! As this sort of thing has happened to me a couple of times, I wonder if there is some sort of reporting mechanism (e.g. an env variable) that I could enable which would put Cocoa in a verbose mode that would report on such things, or better yet get Xcode to halt the program when an undefined selector is used on a valid object?

Alternatively, is there a guide to advanced cocoa debugging tips available somewhere?

Calling a method on an object that has no implementation of that method should generate an exception, that should be printed in the log when running inside Xcode. Or you could override NSApplication - (void)reportException:(NSException *)exception and handle it on your own.

The suggestions by @galad87 are good. I would add that you could set a symbolic breakpoint on -[NSObject doesNotRecognizeSelector:]. I haven't actually tried that, but in theory it should work.

Cocoa [NSView viewDidLoad] debugging
 
 
Q