一、 Flag
if DEBUG
let name = "name"
print("实际内存大小", MemoryLayout.size(ofValue: name))
print("内存对齐大小", MemoryLayout.alignment(ofValue: name))
print("分配的内存大小", MemoryLayout.stride(ofValue: name))
endif
可以在 Build settings → swift compiler - custom flags 中设置Flag(eg: MYDEBUG)
image.png二、System
if os(macOS) || os(tvOS) || os(iOS) || os(watchOS)
...
endif
三、是否能import
if canImport(SnapKit)
...
endif
四、芯片架构
if arch(x86_64) || arch(arm) || arch(arm64) || arch(i386)
...
endif
五、Swift编译版本/版本
暂不清楚 compiler() 与 swift() 的区别
if compiler(>=5.4.2) || compiler(<1.0)
...
endif
if swift(>=5.4)
...
endif
六、目标环境
目前应该只有模拟器simulator一个值
if targetEnvironment(simulator)
...
网友评论