LoginSignup
20
19

More than 5 years have passed since last update.

SwiftでPreprocessor Macrosを使う

Last updated at Posted at 2016-06-30

ハマったのでメモ。

Preprocessor Macrosとは

Build Settings にある DEBUG などのフラグの設定です。

macros.png

SwiftからPreprocessor Macrosを使用するには

Other Swift Flags-D{フラグ名} を設定します。

swift.png

コードから以下のように使用することができます。

var baseURL: NSURL {
    #if STAGING
        return NSURL(string: "https://hogehoge.stg.piyopiyo")!
    #else
        return NSURL(string: "https://hogehoge.piyopiyo")!
    #endif
}

参考

ios - #ifdef replacement in swift language - Stack Overflow

20
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
19