Zeophlite
Zeophlite

Reputation: 1617

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];

Upvotes: 2

Views: 141

Answers (2)

drekka
drekka

Reputation: 21883

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

Upvotes: 0

Justin Spahr-Summers
Justin Spahr-Summers

Reputation: 16973

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.

Upvotes: 1

Related Questions