Swift version: 5.2
Swift gives us the
#if swift build configuration option, which lets you compile certain code only if a specific version of the Swift compiler is detected. This is particularly useful for libraries that need to support multiple incompatible versions of Swift at the same time, because only one version of their code will ever be compiled.
In the example below, the
print() code will display one of two messages depending on whether you're using an old version of Swift:
#if swift(>=5.0) print("Running Swift 5.0 or later") #else print("Running old Swift") #endif
SPONSORED ViRE offers discoverable way of working with regex. It provides really readable regex experience, code complete & cheat sheet, unit tests, powerful replace system, step-by-step search & replace, regex visual scheme, regex history & playground. ViRE is available on Mac & iPad.
Available from iOS 7.0
This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.
Link copied to your pasteboard.