Monday, April 23, 2018

Forcing Compiler Errors in Swift

Erica Sadun:

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 or FIXME (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

1 Comment RSS · Twitter

Leave a Comment