Reputation: 18507
I've read that sending messages to nil is allowed in ObjC and I understand that this is a part of the language and that there has been controversy about it, pro and con. I don't want to open up a discussion about any of that.
I just want to know if there is a way, short of always having to test if (presumedInstance != nil)
, that I can get errors when trying to send a message to nil? It is not helping me when coding that I don't get errors - makes it harder to determine where the code flaw is, etc.
Perhaps a setting or script in XCode?
Upvotes: 1
Views: 241
Reputation: 29883
No, there's no way to do this. In fact, it's a very important feature of Objective-C. I'd actually argue it's more important for you to do the testing (if (object)
, which is the same as if (object != nil)
) because it forces you to consider the inputs and outputs of your functions and methods, and the code paths your application goes through. It might be frustrating at first, but it's one of the things you get used to, and it makes life much easier.
Upvotes: 2
Reputation: 22820
What about trying assertions, like with NSAssert
?
NSAssert Generates an assertion if a given condition is false.
Usage :
NSAssert(condition, desc)
Parameters :
condition
: An expression that evaluates to YES or NO.desc
: An NSString object that contains an error message describing the failure condition.
Reference :
Upvotes: 0