What is swift replacement of traditional c-style #error
keyword?
I need it to raise compile-time error when pre-defines failed:
#if CONFIG1
...
#elseif CONFIG2
...
#else
#error "CONFIG not defined"
#endif
Great news - if you're using Swift 4.2 or newer you can now use #error()
and #warning()
For example:
let someBoolean = true
#warning("implement real logic in the variable above") // this creates a yellow compiler warning
#error("do not pass go, do not collect $200") // this creates a red compiler error & prevents code from compiling
Check out the implemented proposal here https://github.com/apple/swift-evolution/blob/master/proposals/0196-diagnostic-directives.md
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With