Forcing Compiler Errors in Swift
Swift’s newly adopted
#error
and#warning
directives represents a big step up from current practices, which often rely on run-time rather than compile-time feedback.[…]
Here’s an example I discovered from John Estropia. (He, in turn, cribbed it from one of his co-workers.) He uses conditional compilation to set a
TODO
orFIXME
(or whatever) typealias then uses it in-line at points where a debug build should compile and release builds should error:#if DEBUG internal typealias TODO<T> = T #endif print("Remove this later") as TODO