一个简单且非常有用的属性包装器,用于存储配置。它易于使用。
pod 'LuckyUserDefaultsStorable'
- 定义数据格式
struct Config: Codable {
var host: String
// More properties
}
- 使用属性包装器
@UserDefaultsStorable(key: "Config.defoult", defaultValue: Config(host: "https://www.google.com"))
static var defoult: Config
/// When suitName of UserDefaults is empty, UserDefaults.standard is used.
let suitName: String?
/// The key used for saving.
let key: String
/// The default value returned when UserDefaults does not have a value.
let defaultValue: T
/// Please use it with Codable-compliant data.
public struct UserDefaultsStorable<T: Codable>