LoginSignup
0

More than 3 years have passed since last update.

BundleConfigurationとSchemeの関係性がわからないから調べた

Last updated at Posted at 2019-08-28

タイトルとおりです
BundleConfigurationとSchemeの関係性がわからなかったので調べました
個人的メモなので雑です

関係性とユースケース

アプリを作るとき複数の環境向けに作りたい場合があります
例えば、自社確認用・先方確認用・リリース用や開発サーバ・本番サーバを使う2種類の環境用など
他にも複数環境用意することはあるかと思います

そんなときXcodeのスキームを使うと便利で、まず用意したい環境数分BuildConfigurationを設定する
初期設定ではDebugとReleaseがあるようです

ざっくりですがこの記事をみて理解しました
*写真はすべて同記事から引っ張ってきたものです。途中元記事の文章が入ってるため読みづらいかもしれません

3つConfigurationを設定する場合は

スクリーンショット 2019-08-28 17.14.53.png

Schemeも一つ追加

スクリーンショット 2019-08-28 17.20.07.png

スクリーンショット 2019-08-28 17.21.01.png

各SchemeとBuildConfigurationを紐付ける

スクリーンショット 2019-08-28 17.23.13.png

スクリーンショット 2019-08-28 17.24.50.png

これでSchemeで環境を切り替えられる、つまり、Schemeを変えることでBuild環境を切り替えるられるようになりました

ここから各環境ごとのBundleIDを設定してSchemeで切り替えたり
他にもScheme一つ、BuildConfiguration3つで切り替えたりと色々とできることやり方はあるようですが
この記事ではここまで

BuildConfigurationとSchemeを使わないとどうなるか

Some naive things I did that wasted a lot of time

1.In one of my projects, I created two separate targets, one for the paid version and another for the free version. This actually worked, but it ended up being far more work than was needed.

2.Really early in my developer days, I actually duplicated all of the source files just for the free version. I don’t need to tell you why that’s a horrible idea.

Learn from my mistakes, and don’t do either of these! Read this article and follow these steps. The end result will be much more manageable.

参照: https://medium.com/practical-ios-development/some-practical-uses-for-xcode-build-schemes-and-build-configurations-swift-e50d15a1304f

参照記事

https://qiita.com/odorry/items/fc332e1084ebf74e8f65
https://qiita.com/uasi/items/79aecac40f1b2a5f929b
紹介した英語記事もわかりやすく、BuildConfigurationとSchemeの関係性がわからなかったですが、この記事のおかげで理解できました
よくいう英語と日本語の文章の構成の違いなのか...
'The Difference Between Build Schemes & Build Configurations'から読むことをおすすめします
https://medium.com/practical-ios-development/some-practical-uses-for-xcode-build-schemes-and-build-configurations-swift-e50d15a1304f

追記

このあとはソースコード内で環境ごとの条件分岐ができるように、条件付きコンパイルフラグをSwiftコンパイラに渡していく設定をしていく予定だけど
それはこの記事なんかを参考にしてもらうとすぐにできると思います
参考: https://qiita.com/Todate/items/a2e6a26731c79bd23e02

1つ注意点があって、上の記事内ではそのためにProcessor MacrosとOther Swift Flagsに変更を加えていますがこれはXcode7までの話で
Xcode8からはActive Compilation Conditionsの設定に変更を加えるだけで済むらしい
参考: https://dev.classmethod.jp/smartphone/iphone/xcode-8-active-compilation-conditions/

色々記事を見ると、Processor MacrosとOther Swift Flagsを使ってみたり、Active Compilation Condition使ってみたり、両方とも使ってたりしている記事があって混乱していたけど
自分で実際にXcode10.3を使って試してみたところActive Compilation Conditionsに変更を加えるだけでできたからActive Compilation Conditionsだけでいいんだと思う

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
0