Reputation: 12093
I am developing a Framework for the company that I work for that they can use, and I want to be able to print out some runtime warnings to the console if they have lets say passed the wrong parameter into a method I have made, like if they pass nil in when they should have passed self. I know I can do NSLog(), and the preprocessor #warning. But is there anything else I can do to warn the user as #warning will always show up in the editor unless I put it in some preprocessor if statement.
Upvotes: 0
Views: 87
Reputation: 6822
You should use NSAssert
for this. It will halt the execution if in debug mode, when running without a debugger, it will print the error to the device log.
- (void)someSelector:(id)param)
{
NSAssert(param != nil, @"Parameter should always be non-nil");
// do stuff with param
}
If you prefer, you can also compile for release with NS_BLOCK_ASSERTIONS
, then no assertions will be present at all (nothing will be printed, and the tests won't even be compiled). That way you can avoid the overhead of checking it in the final product.
Upvotes: 1