#if <#T##condition###>
#elseif <#T##condition###>
#else
#endif
方法 | 可选参数 |
---|---|
os() | macOS, iOS, tvOS, watchOS, Linux |
arch() | x86_64, arm, arm64, i386 |
swift() | >= 某个版本 |
#if DEBUG
#else
#endif
自定义符号
使用自定义的符号 Custom_Compile_Symbol
进行条件编译,在 Build Settings
-> Swift Compiler - Custom Flags
, 在 Other Swift Flags
中添加 -D Custom_Compile_Symbol
#if Custom_Compile_Symbol
print("添加 Custom_Compile_Symbol 执行此模块")
#else
print("未添加 Custom_Compile_Symbol 执行此模块")
#endif