Skip to content

Instantly share code, notes, and snippets.

@mdznr
Last active February 16, 2022 23:31
Show Gist options
  • Save mdznr/eba8535d7ddd3f512ddfc89c85219767 to your computer and use it in GitHub Desktop.
Save mdznr/eba8535d7ddd3f512ddfc89c85219767 to your computer and use it in GitHub Desktop.
Compares the different behaviors of the various assertion functions in Swift
function debug release release
Optimization Level -Onone -O -Ounchecked
assert() YES NO NO
assertionFailure() YES NO NO**
precondition() YES YES NO
preconditionFailure() YES YES YES**
fatalError()* YES YES YES
Value Meaning
YES Terminates
NO Does not terminate

* Not really an assertion. It’s designed to terminate code execution always, no matter what.

** The optimizer may assume that this function will never be called.

Sources:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment