测试已测试 | ✓ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布日期上次发布 | 2016年10月 |
SPM支持 SPM | ✓ |
由 Leroy Jenkins,Jelle Vandebeeck 维护。
Stella 包含一套可用于 Swift 编写 iOS 开发的工具。
Stella 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile
pod 'Stella', '~> 1.1'
我们可以用更干净的方式来使用 NSUserDefaults
。通过扩展 DefaultsKeys
类定义用户默认值。
extension DefaultsKeys {
// Writes a string object to the defaults with the 'stringValue' key.
static let stringValue = DefaultsKey<String?>("stringValue")
// Writes an integer to the defaults with the 'integerValue' key.
static let integerValue = DefaultsKey<Int?>("integerValue")
// Writes a double to the defaults with the 'doubleValue' key.
static let doubleValue = DefaultsKey<Double?>("doubleValue")
// Writes a float to the defaults with the 'floatValue' key.
static let floatValue = DefaultsKey<Float?>("floatValue")
// Writes a bool to the defaults with the 'booleanValue' key.
static let booleanValue = DefaultsKey<Bool?>("booleanValue")
// Writes a date object to the defaults with the 'dateValue' key.
static let dateValue = DefaultsKey<NSDate?>("dateValue")
}
您可以使用 Defaults
类的 subscript
来从/向 NSUserDefaults
读取/写入数据。
Defaults[.stringValue] = "A string value"
print(Defaults[.stringValue]) // Prints 'A string value'
Defaults[.integerValue] = 123
print(Defaults[.integerValue]) // Prints '123'
Defaults[.doubleValue] = 123.123
print(Defaults[.doubleValue]) // Prints '123.123'
Defaults[.floatValue] = 123.321
print(Defaults[.floatValue]) // Prints '123.312'
Defaults[.booleanValue] = true
print(Defaults[.booleanValue]) // Prints 'true'
Defaults[.dateValue] = NSDate()
print(Defaults[.dateValue]) // Prints '1996-12-19T16:39:57-08:00'
我们可以用更干净的方式来使用 Keychain
。通过扩展 Keys
类定义用户默认值。
extension Keys {
// Writes a string object to the keychain with the 'stringValue' key.
static let stringValue = Key<String?>("stringValue")
}
您可以使用 Keychain
类的 subscript
来从/向 Keychain
读取/写入数据。
Keychain[.stringValue] = "A string value"
print(Keychain[.stringValue]) // Prints 'A string value'
这个便捷的本地化函数可以让您快速本地化一个键。
let key = "this_is_your_localization_key"
print(key.localizedString)
// The debug console will print the localized
// string found in your .strings file.
将一些额外内容添加到您的调试输出中。有三个额外可供使用的函数。
printAction("This is a user action.")
// The debug console will print `🎯 This is a user action.`
printBreadcrumb("This is your breadcrumb.")
// The debug console will print `🍞 This is your breadcrumb.`
printError("This is an error.")
// The debug console will print `🔥 This is an error.`
printQuestion("This is a question")
// The debug console will print `❓ This is an question.`
您可以简单地指定打印级别,例如
Output.level = .verbose
只打印错误
Output.level = .error
或者只是关闭所有内容,这对于单元测试非常有用。
Output.level = .nothing
要了解打印的内容以及它们对应的级别,请查看 PrintSpec
。
以下是我们的待办事项列表概览。
sharedInstance
更可配置。Jelle Vandebeeck, [email protected]
Stella 可在 MIT 许可下使用。有关更多信息,请参阅 LICENSE 文件。