LoginSignup
3
0

More than 5 years have passed since last update.

error: conditional compilation flags must be valid Swift identifiers が出たら

Posted at

現象

Xcode8からXcode9に移行したときに、以下のようなビルドエラーが発生しました。

<unknown>:0: error: conditional compilation flags must be valid Swift identifiers (rather than '-D')
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1

Xcode8では問題なくビルドできるプロジェクトです。

原因

Build Settings のActive Compilation Conditions-D DEBUG と書かれていた。

ACC.png

-Dを削除して、DEBUGだけにしたらエラーが消えました。

説明

Active Compilation Conditions は以下のようなマクロで分岐させるときに使うフラグ文字列です。

#if DEBUG
  // デバッグビルド時のみの処理
#endif

Xcode8以降はデフォルトでDEBUGが入っています。

default.png

Xcode7以前ではOther Swift Flags の方に -D DEBUG のように指定していましたが、Active Compilation Conditions には-Dが必要ありません。同じノリでActive Compilation Conditions-D DEBUGと指定すると、"-D"と"DEBUG"という2つの文字列を設定していると解釈されます。

Xcode8ではActive Compilation Conditionsに"-D"という文字列を設定していても別に怒られなかったのですが、Xcode9から1はハイフンから始まる文字列はコンパイル時に蹴るようになったようです。

因みに、Active Compilation ConditionsOther Swift Flagsの-D指定はどちらかが優先ということではなく、共存できるようでした。

検証環境

  • macOS Sierra Ver. 10.12.6
  • Xcode8.3.3
  • Xcode9.0

  1. 正確に言うとXcodeというよりもSwiftコンパイラのバージョンに依存するものと思われます 

3
0
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
3
0