我知道Swift有预处理器指令来检查操作系统:
#if os(iOS)
...
#elseif os(OSX)
...
#endif
Run Code Online (Sandbox Code Playgroud)
但是,在线搜索之后,我发现没有什么可以检查操作系统是Ubuntu.有没有办法做到这一点?我知道swift最近才开始研究Ubuntu,所以我意识到在撰写本文时可能没有办法.
在Swift中,#if ... #endif不是预处理程序语句,而是包含"条件编译块".os()平台条件的有效参数(目前)记录为
macOS, iOS, watchOS, tvOS, Linux
Run Code Online (Sandbox Code Playgroud)
因此#if os(Linux)检查Linux平台.一个典型的例子是
#if os(Linux)
import Glibc
#else
import Darwin
#endif
Run Code Online (Sandbox Code Playgroud)
在Linux和Apple平台上从C库导入函数.
| 归档时间: |
|
| 查看次数: |
1027 次 |
| 最近记录: |