美文网首页
Xcode中Active Compilation Conditi

Xcode中Active Compilation Conditi

作者: 小杰杰杰 | 来源:发表于2019-10-20 17:19 被阅读0次

Xcode中的,都是用于 条件编译时,所需要定义变量时,有两个:
Active Compilation Conditions和Preprocessor Macros

两者有何区别

Active Compilation Conditions vs Preprocessor Macros

Super Preprocessor Directives with Xcode 8 – Derrick Ho – Medium

原来是:

对于OBJC,用:Preprocessor Macros

对于SWIFT,用:Active Compilation Conditions

xcode – #ifdef replacement in the Swift language – Stack Overflow

SWIFT_ACTIVE_COMPILATION_CONDITIONS

“Active Compilation Conditions” is a new build setting for passing conditional compilation flags to the Swift compiler.”

是Xcode8中新增的。

Using Swift with Cocoa and Objective-C (Swift 4): Interacting with C APIs

“Preprocessor Directives

The Swift compiler does not include a preprocessor. Instead, it takes advantage of compile-time attributes, conditional compilation blocks, and language features to accomplish the same functionality. For this reason, preprocessor directives are not imported in Swift.”

swift Active Compilation Conditions

Xcode 8: New build settings and analyzer improvements – miqu.me

之前swift中定义自定义变量时,都是放在OTHER_SWIFT_FLAGS中,现在都可以改用SWIFT_ACTIVE_COMPILATION_CONDITIONS的Active Compilation Conditions了。

xcode – Any way to do true conditional compilation in Swift 3? – Stack Overflow

“Active Compilation Conditions is a new build setting for passing conditional compilation flags to the Swift compiler. Each element of the value of this setting passes to swiftc prefixed with -D, in the same way that elements of Preprocessor Macros pass to clang with the same prefix. (22457329)”

【总结】

  • 在之前OC时代(编译器是clang),条件编译所用到的变量定义,都是通过:GCC_PREPROCESSOR_DEFINITIONS的Preprocessor Macros去定义的;
  • 后来swift中(编译器是swiftc),最开始时是用:OTHER_SWIFT_FLAGS的Other Swift Flags中定义的(加上-DXXX)
  • Xcode 8中又更新为,换用SWIFT_ACTIVE_COMPILATION_CONDITIONS的Active Compilation Conditions去定义变量XXX即可(不需要加-D)。

此处,Xcode9中,当前代码是swift,用的编译系统也是swift,所以变量定义是用Active Compilation Conditions,而不是Preprocessor Macros。

相关文章

网友评论

      本文标题:Xcode中Active Compilation Conditi

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