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
- 以下のように設定する
使い方
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
}