feat: added random Color and data type to the Store

This commit is contained in:
Serhiy Mytrovtsiy
2023-03-25 16:28:21 +01:00
parent 5105c8c20d
commit 895eaba528
2 changed files with 12 additions and 0 deletions

View File

@@ -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)

View File

@@ -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
}