最新消息:VPS服务器又从fzhost.net换回Linode了,主题仍用朋友推荐的大前端D8

【已解决】Xcode中Active Compilation Conditions和Preprocessor Macros的区别

Xcode crifan 73浏览 0评论
折腾:
【已解决】Xcode项目条件编译出错:Use of unresolved identifier
期间,需要
搞清楚,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_DEFINITIONSPreprocessor Macros去定义的;
  • 后来swift中(编译器是swiftc),最开始时是用:OTHER_SWIFT_FLAGS的Other Swift Flags中定义的(加上-DXXX)
  • Xcode 8中又更新为,换用SWIFT_ACTIVE_COMPILATION_CONDITIONSActive Compilation Conditions去定义变量XXX即可(不需要加-D)。
此处,Xcode9中,当前代码是swift,用的编译系统也是swift,所以变量定义是用Active Compilation Conditions,而不是Preprocessor Macros。

转载请注明:在路上 » 【已解决】Xcode中Active Compilation Conditions和Preprocessor Macros的区别

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
16 queries in 0.174 seconds, using 9.78MB memory