From 895eaba528abc507ed5bb07e9b5907bfc072eb4e Mon Sep 17 00:00:00 2001 From: Serhiy Mytrovtsiy Date: Sat, 25 Mar 2023 16:28:21 +0100 Subject: [PATCH] feat: added random Color and data type to the Store --- Kit/plugins/Store.swift | 8 ++++++++ Kit/types.swift | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/Kit/plugins/Store.swift b/Kit/plugins/Store.swift index 59f9177a..c9816027 100644 --- a/Kit/plugins/Store.swift +++ b/Kit/plugins/Store.swift @@ -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) diff --git a/Kit/types.swift b/Kit/types.swift index e9fa43a5..e7f831dc 100644 --- a/Kit/types.swift +++ b/Kit/types.swift @@ -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 }