Objective C Make message to nil generate run time error
Is it possible to make messages sent to nil generate some sort of error in run time? I want it for the debugging pur开发者_如何学编程pose.
You may want to look into the NSZombieEnabled
environment variable.
As @jtbandes said, nil
messages are generally a good thing because you can avoid going if (object) [object message]
and instead just use [object message]
. But a far more important thing to watch out for is sending a message to an object that once existed but has now been freed (without the pointer being nil
-ed out). NSZombieEnabled
lets you find out when this has happened.
精彩评论