我认为使用枚举是一种很好的方法,如下所示:
enum Constants {
enum SubConstants {
static let Constant1234 = "Hello sir!"
}
}
Run Code Online (Sandbox Code Playgroud)
然后像这样使用它:
print(Constants.SubConstants.Constant1234)
Run Code Online (Sandbox Code Playgroud)
如果你有一个服务器根据国家,用户等提供常量,那么plist可能是一个很好的方法.
如果您想使用plist,可以按照本指南操作.
更新:
Adnan如何指出,你不应该使用枚举来存储常量,因为它不是最佳实践,而是你应该使用结构:
struct Constants {
struct SubConstants {
static let Constant1234 = "Hello sir!"
}
}
Run Code Online (Sandbox Code Playgroud)