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

More than 1 year has passed since last update.

【Swift】APIキー専用の構造体を作って管理する方法

Last updated at Posted at 2021-10-22

Swiftで大事なAPIキー専用の構造体を作って管理する方法。

大事なAPIキーをまとめた構造体を作ってファイルに書いておけば、GitHubなどで公開する際に、そのファイルだけ.gitignoreで除外しておけば、漏れる心配もないので安心。

APIキーを集約した構造体

import Foundation

struct ImportAPI {
    public static let API_KEY = "xxxxxxxxxxxxxxxxxxxx"
    public static let API_TEST_KEY = "xxxxxxxxxxxxxxxxxxxx"
}

APIを呼び出す時のコード

print(ImportAPI.API_KEY)
print(ImportAPI.API_TEST_KEY)

Swiftのお役立ち情報

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