开发者

How can I make iPhone simulator generate an error when I try to dereference a nil object?

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜