I have a method that takes a BOOL parameter and I want to make sure it is not nil in the call.
-(void)setNetworkFilterWithName:(NSString *)nameOfFilter toState:(BOOL)newState
I can’t use a NSParameterAssert(newState); because it will assert when the BOOL is false.
So I do this:
NSParameterAssert((newState == true) || (newState == false));
Is there a more elegant way of checking for this?
A
BOOLis a value type, not a pointer so it can not beNULL. It will only be false which is zero or not false which is non zero. No need to check it.Edit:
If you would like to check and make sure that the
BOOLisYESorNOthat could prove useful especially in situations where anNSNumberis accidentally passed, which will always evaluate to true if it is not nil.NSParameterAssert(!newState || newState == YES);