How to use precondition and assert in Swift

Issue #553

Read Swift asserts - the missing manual

1
2
3
4
5
6
7
                        debug	release	  release
function -Onone -O -Ounchecked
assert() YES NO NO
assertionFailure() YES NO NO**
precondition() YES YES NO
preconditionFailure() YES YES YES**
fatalError()* YES YES YES

And from Interesting discussions on Swift Evolution

– assert: checking your own code for internal errors

– precondition: for checking that your clients have given you valid arguments.

Read more

Comments