Is there any way 开发者_开发问答to get the iPhone simulator to give an error or log a message when I try to access a method of a variable that is nil?
e.g.,
MyClass *p = nil;
[p doSomething];
No, there isn't. This is expected behavior for Objective-C, and lots of code (including Apple's frameworks) depends on it. If you somehow were to disable it, many terrible things could happen. Instead, learn to familiarize yourself with it and incorporate it in your code.
Not sure if it's what you are looking for, but zombies might be helpful. Check out:
http://iosdevelopertips.com/debugging/tracking-down-exc_bad_access-errors-with-nszombieenabled.html
精彩评论