美文网首页
OC、Swift设置编译条件

OC、Swift设置编译条件

作者: 思绪_HY | 来源:发表于2018-11-05 15:03 被阅读10次

在 OC 中我们设置编译条件,一般通过修改

image

Preprocessor Macros 中对应的宏定义。但是在Swift中,预处理的宏定义已经无效了,主要是 Swift 不在包含预处理的过程

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

那么我们该如何在编译时做条件选择呢?

Swift中设置编译条件

在 Xcode 8 之前我们可以通过设置

image

Swift Compiler - Custom Flags 来设置我们需要用到的条件,在 Other Swift Flags 中设置 -D ADHOC

  1. Go to your project / select your target / Build Settings / search for Custom Flags
  2. For your chosen target set your custom flag using -D prefix (without white spaces), for both Debug and Release
  3. Do above steps for every target you have

在 Xcode 8 之后我们可以直接设置

image

Stackoverdflow 上边的回答

image

相关文章

  • OC、Swift设置编译条件

    在 OC 中我们设置编译条件,一般通过修改 Preprocessor Macros 中对应的宏定义。但是在Swif...

  • Swift:与OC混编

    目录一,条件编译二,KVO/KVC三,Swift调用OC四,OC调用Swift五,字符串六,多线程 一,条件编译 ...

  • Swift--001:Swift编译 & SIL分析

    Swift与OC编译区别 swift与oc编译区别Swfit使用前端编译器swiftc,降级编译成IR,再通过后端...

  • Swift5.1 学习笔记(一)

    基础语法以及汇编原理 oc与swift汇编的区别 编译分为前端编译、后端编译。下面的图就描述了oc和swift编译...

  • Swift进阶02: 类、对象、属性

    Swift编译过程 编译过程(OC、Swift的区别) OC中通过clang编译器,编译成IR,然后再生成可执行文...

  • Swift的优化

    swift 比oc更快,但是swift编译比oc时间长因为swift使用Whole Module Optimiza...

  • oc 继承 swift 类

    oc 继承 swift 类 项目中使用 oc 继承 swift 类编译器报错: oc 继承前增加 objc_sub...

  • Swift和OC的区别:

    Swift与OC之间的关系: Swift 与 OC共同运行在同一编译环境下,虽然 Swift 现在已经更新到4.0...

  • Swift5.1 - oc到swift过渡

    条件编译 系统版本号检查 MARK、TODO、FIXME swift调用oc 新建1个桥接头文件,文件名格式默认为...

  • Swift类结构探究

    对于iOS开发,OC语言前端使用Clang编译器,swift语言前端使用swift编译器swiftc,这两个编译器...

网友评论

      本文标题:OC、Swift设置编译条件

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