mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: added random Color and data type to the Store
This commit is contained in:
@@ -37,6 +37,10 @@ public class Store {
|
||||
return (!self.exist(key: key) ? value : defaults.integer(forKey: key))
|
||||
}
|
||||
|
||||
public func data(key: String) -> Data? {
|
||||
return defaults.data(forKey: key)
|
||||
}
|
||||
|
||||
public func set(key: String, value: Bool) {
|
||||
self.defaults.set(value, forKey: key)
|
||||
}
|
||||
@@ -49,6 +53,10 @@ public class Store {
|
||||
self.defaults.set(value, forKey: key)
|
||||
}
|
||||
|
||||
public func set(key: String, value: Data) {
|
||||
self.defaults.set(value, forKey: key)
|
||||
}
|
||||
|
||||
public func reset() {
|
||||
self.defaults.dictionaryRepresentation().keys.forEach { key in
|
||||
self.defaults.removeObject(forKey: key)
|
||||
|
||||
@@ -207,6 +207,10 @@ extension Color: CaseIterable {
|
||||
]
|
||||
}
|
||||
|
||||
public static var random: Color {
|
||||
Color.allColors[.random(in: 0...Color.allColors.count)]
|
||||
}
|
||||
|
||||
public static func fromString(_ key: String, defaultValue: Color = .systemAccent) -> Color {
|
||||
return Color.allCases.first{ $0.key == key } ?? defaultValue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user