LoginSignup
15
15

More than 5 years have passed since last update.

xcconfigでビルド設定を外部ファイル化する

Last updated at Posted at 2015-11-02

debug用とrelease用のxcconfigを作る

  • 新規ファイル作成 > iOS > Other > Configuration Setting File
  • 「Config.debug.xcconfig」と「Config.release.xcconfig」を作成する
  • 各xcconfigファイルにビルド設定を記述する

Config.debug.xcconfig

OTHER_SWIFT_FLAGS = $(inherited) "-D" "DEBUG"

Config.release.xcconfig

OTHER_SWIFT_FLAGS = $(inherited)

ProjectのConfigurationsの設定で、xcconfigを使うように設定する

  • Project > Info > Configurations
  • 以下のように設定する

Artboard 1.png

使い方

API.swiftなどを作って、DEBUGが定義されているかどうかで、URL定数の値を変化させます。

# API.swift

class API : NSObject {
  #if DEBUG
  static let URL = "http://debug.hoge.com/api"
  #else
  static let URL = "http://production.hoge.com/api"
  #endif
}
15
15
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
15
15