Most of the assertions I write are based on a conditional expression, like so:
- NSParameterAssert(key != nil);
- NSAssert(count <= MAX_FACTOR_COUNT, @"Too many factors");
- NSAssert1(size % 2 == 1, @"Cannot create hexagonal board with even size %i", size);
But I also have quite a few cases of triggering an assertion failure with a hard-coded false value:
- NSAssert(false, @"Abstract method invoked");
- NSAssert(false, @"Unimplemented");
- NSAssert(false, @"Invalid operation for this subclass");
This feels wrong to me. I feel like I should be saying something like this instead:
- NSAssertFail(@"Abstract method invoked");
- NSAssertFail(@"Unimplemented");
- NSAssertFail(@"Invalid operation for this subclass");
My question is: How have people traditionally dealt with this? What do you name a preprocessor macro that wraps NSAssert(false, ...)
?
Is NSAssertFail()
a good name?