1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Swift] custom flagsを利用してスキーマ毎に英/日アプリをビルドするcustom flags active compilation conditions

Posted at

概要

個人開発のAppで日本用(日本語)と海外用(英語)で分けてリリースしたかった。
Geminiに
Project > Build Settings > Swift Compiler -Custom Flags
からスキーマ毎にコンパイルフラグを設定できると教えてもらったが、ビルドで設定に反映されるまで時間がかかったの書き留めておく

Xcode: Version 16.2

流れ

1.スキーマを作成

Project > Info > Configuration から、任意のスキーマを作成
今回は、Release_JPとRelease_ENを作成した
スクリーンショット 2025-09-13 18.34.12.png

2. コンパイルフラグの設定

概要にも記したように、
Project > Build Settings > Swift Compiler -Custom Flags
からスキーマ毎にコンパイルフラグを設定
今回は、
Release_JP: JAPANESE
Release_EN: ENGLISH
とした
スクリーンショット 2025-09-13 18.36.43.png

3.ビルド時のスキーマ設定

ここの作業が必要であると気づくのに時間がかかった。

3.1 トップバーのTargetマーク?をクリック

スクリーンショット 2025-09-13 18.41.10.png

3.2 各ビルド時のスキーマを設定

XcodeのRunボタンから実行したい時
スクリーンショット 2025-09-13 18.45.00.png

Archiveするとき
スクリーンショット 2025-09-13 18.46.06.png

4.コードでの利用方法

登場する文言をまとめて管理する構造体を作成し、
JAPANESEの時とENGLISHの時で表示する文言を返す実装を行なった

struct LocalizedStrings {
    
    static let close: String = {
        #if JAPANESE
        return "閉じる"
        #elseif ENGLISH
        return "Close"
        #else
        // Default or fallback string
        return "Close"
        #endif
    }()
    ...

参考にした記事

https://zenn.dev/kyome/articles/0b6a689776c9c69b4026
こちらのKyome sanの記事を一部参考にしました

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?