Claims in Swift

I tested the statements in Swift, but I'm a bit confused. Could you explain to me the difference between the functions assert, assertionFailureand fatalError?

I know about the attribute @noreturn( beautifully explained by Seven Oglesby), but I don't understand when these functions are evaluated and when they are ignored.

Functions assertand fatalErroroccurred only in debug mode, I tested this behavior, and this is true. But assertionFailurealso stops the program in the release configuration. The documentation remains:

A fatal error has occurred, and program execution should stop in debug mode. In optimized builds, this is noop.

Then I do not understand why this method is not ignored in non-debug mode. Does anyone have any experience?

+4
source share
1 answer

Actually, it assertis evaluated only in debug mode, but it fatalErrorhappens regardless of configuration. This is intentional.

However, it assertionFailurealso happens regardless of configuration, despite the documentation you quote. As far as I can tell, the behavior assertionFailureis incorrect, or the documentation is incorrect.

+4
source

All Articles