0

Sometimes I like to put NSAssert(NO, @"this should never happen") in a block of code that should never be reached. Is there a better alternative for such unconditional asserts in Objective-C? I would like something like NSTerminate(@"this should never happen") - a convenient function which prints a message and terminates the program unconditionally.

1
  • 1
    NSAssert(NO,...) is the traditional way to write this.
    – Rob Napier
    Commented Oct 3, 2024 at 14:27

1 Answer 1

2

IMO, I think NSAssert is appropriate because it is only in Development (by default). You do not want an unexpected crash in Production if the block of code changes in the near future somehow, do you?

However, you can take a look at NSException raise here:

[NSException raise: @"InvalidBlock" fromat: @"This should never happen"];

Not the answer you're looking for? Browse other questions tagged or ask your own question.