示例工程 01-toolchain-and-mindset
01-toolchain-and-mindset/Sources/Ch01Kit/BuildConditions.swift
/// 本章关心的编译期条件;`isActive` 的结果在编译期就固定了。
public enum BuildCondition: String, CaseIterable, Sendable {
case debug
case release
case swiftSix
case appleSilicon
case foundation
/// 条件是否在本次编译中成立。
public var isActive: Bool {
switch self {
case .debug:
#if DEBUG
return true
#else
return false
#endif
case .release:
#if DEBUG
return false
#else
return true
#endif
case .swiftSix:
#if swift(>=6.0)
return true
#else
return false
#endif
case .appleSilicon:
#if arch(arm64)
return true
#else
return false
#endif
case .foundation:
#if canImport(Foundation)
return true
#else
return false
#endif
}
}
/// 中文短标题,用于 Demo 输出与正文表格。
public var title: String {
switch self {
case .debug:
return "DEBUG 断言"
case .release:
return "release 构建(!DEBUG)"
case .swiftSix:
return "Swift 6 语言模式"
case .appleSilicon:
return "arm64 目标"
case .foundation:
return "Foundation 可导入"
}
}
}