【发布时间】:2018-12-02 22:56:10
【问题描述】:
我将在整个应用程序中使用一些字符串名称作为通知和用户默认名称。
我听说为了类型安全,将notification 名称或UserDefaults 键名称定义为静态字符串并将它们作为类或结构的一部分是一种很好的做法。
为 Notification 和 UserDefault 名称处理字符串名称的最常用方法是什么?
我曾考虑将它们作为全局变量放在我的 AppDelgate 类中,如下所示......
let MY_STRING_NAME = "My string name"
class AppDelegate: UIResponder, UIApplicationDelegate {}
/// Then just use MY_STRING_NAME in other classes.
或者
class SomeClass {
let myStringName:String = "My string name"
}
/// Then use myClassInstance.myStringName
最好的方法是什么?
【问题讨论】:
标签: swift encapsulation