LoginSignup
4
2

More than 5 years have passed since last update.

Swift3でコードからアプリ名を取得

Posted at

ググってもObjective-Cのやり方が多かったのでSwift用のものをメモ。

Bundle nameを取得する

Swift
Bundle.main.infoDictionary?[kCFBundleNameKey as String] as? String

Bundle nameはデフォルトでのアプリ名。
意図的にいじっていなければ$(PRODUCT_NAME)が設定されていて、
$(PRODUCT_NAME)はプロジェクト作成時に設定するProduct Nameになっている。

CFBundleDisplayNameを取得する

Swift
Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String

CFBundleDisplayNameはホーム画面で表示される、ローカライズされたアプリの名前。
言語設定によって表示するアプリ名を変えている場合はこちらを使うとよい。
設定していなければnilとなる。

4
2
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
4
2