LoginSignup
19
10

More than 5 years have passed since last update.

iOSで開発向け機能の実装する時に使うテクニック

Last updated at Posted at 2018-12-09

はじめに

  • iosで開発の効率を上げるためにデバッグ機能やダミーのデータを使うことがあると思います。 そのようなコードは本番環境では必要なく、無駄なリソースとなってしまいます。 今回は本番環境に含めないための方法についてまとめます。

環境

Xcode 10.1
Build version 10B61
Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)
Target: x86_64-apple-darwin18.2.0

本番と開発で実行されるコードを分けるとき

  • xcodeのbuild settingsSwift Compiler – Custom FlagsActive Compilation Conditionsでビルドコンフィギュレーション毎にフラグを設定できる 

スクリーンショット 2018-12-09 19.32.41.png

  • 本番と開発環境で分岐を作ることができる
#if DEBUG
 print("開発")
#else
 print("その他")
#endif

本番で開発のファイルを含めたくないとき

  • xcodeのbuild settingsExcluded Source File Namesで除外したいファイルをビルドコンフィギュレーション毎に指定できる スクリーンショット 2018-12-09 20.00.16.png
  • 上記ではDebug+のついたファイルを除外する設定にしている。
  • swiftのファイルはもちろんのこと、asset catalogplistの除外も可能なので余分なリソースを本番環境から除外できる

参考リンク

19
10
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
19
10