美文网首页
Swift条件编译

Swift条件编译

作者: 诗颜语 | 来源:发表于2022-04-14 14:22 被阅读0次

    一、 Flag

    if DEBUG

    let name = "name"

    print("实际内存大小", MemoryLayout.size(ofValue: name))

    print("内存对齐大小", MemoryLayout.alignment(ofValue: name))

    print("分配的内存大小", MemoryLayout.stride(ofValue: name))

    endif

    可以在 Build settingsswift 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)

    ...

    endif

    相关文章

      网友评论

          本文标题:Swift条件编译

          本文链接:https://www.haomeiwen.com/subject/ipmtertx.html