LoginSignup
0
3

More than 5 years have passed since last update.

[iOS][Swift] 意外と知らない? スマートなグローバル変数ファイルの作り方

Last updated at Posted at 2018-11-09

以下のように構造体を作成してから、

Constant.swift

struct K {

    struct UserDefaultsKey {
        static let Settings = "kSetings"
    }

    struct NotificationKey {
        static let Welcome = "kWelcomeNotif"
    }

    struct Path {
        static let Documents = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String
        static let Tmp = NSTemporaryDirectory()
    }
}

以下のように使うだけ。

K.UserDefaultsKey.Settings
K.Path.Documents

参考:
https://stackoverflow.com/a/26252377

0
3
1

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
3