跳到主要内容

Xcode Build System

问题

Xcode 的构建流程是什么?有哪些重要的 Build Settings?

答案

构建流程

重要 Build Settings

设置说明
SWIFT_OPTIMIZATION_LEVEL-Onone(Debug) / -O(Release) / -Osize
DEBUG_INFORMATION_FORMATdwarf(Debug) / dwarf-with-dsym(Release)
STRIP_INSTALLED_PRODUCTRelease 移除符号表
DEAD_CODE_STRIPPING移除未使用代码
ENABLE_BITCODE已弃用(Xcode 14+)
GCC_PREPROCESSOR_DEFINITIONSObjC 预处理宏
SWIFT_ACTIVE_COMPILATION_CONDITIONSSwift 条件编译

条件编译

#if DEBUG
print("Debug mode")
#endif

#if targetEnvironment(simulator)
print("Running on Simulator")
#endif

#if canImport(UIKit)
import UIKit
#endif

常见面试问题

Q1: Debug 和 Release 的主要区别?

答案

  • 优化级别:Debug -Onone(不优化,便于断点),Release -O(优化速度)
  • 符号表:Debug 保留完整符号,Release 生成 dSYM 并 Strip
  • 断言assert 在 Release 中被移除
  • 性能:Release 可能比 Debug 快 2-10 倍

相关链接