I know Swift has preprocessor directives that check the OS :
#if os(iOS)
...
#elseif os(OSX)
...
#endif
But, after searching online, I've found nothing to check is the OS is Ubuntu. Is there a way of doing that ? I know swift has only recently been working on Ubuntu, so I realize that there may not be a way as of this writing.
In Swift, #if ... #endif
are not preprocessor statements, but
enclose a "Conditional Compilation Block". The valid arguments for the os()
platform condition
are (currently) documented as
macOS, iOS, watchOS, tvOS, Linux
Therefore #if os(Linux)
checks for a Linux platform.
A typical example is
#if os(Linux)
import Glibc
#else
import Darwin
#endif
to import functions from the C library on both Linux and Apple platforms.
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