From 51ee0ec8d7bf97a5115b3b3948f5beb6e1131f31 Mon Sep 17 00:00:00 2001 From: Aleksey Zgurskiy Date: Mon, 3 Feb 2020 10:38:15 +0200 Subject: [PATCH 1/2] Add uuid methods --- keychain-kit/Sources/Keychain.swift | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/keychain-kit/Sources/Keychain.swift b/keychain-kit/Sources/Keychain.swift index 4e50e64..da0291f 100644 --- a/keychain-kit/Sources/Keychain.swift +++ b/keychain-kit/Sources/Keychain.swift @@ -46,7 +46,17 @@ public struct Keychain { } public func get(_ key: String) throws -> String { - return String(data: try get(key), encoding: .utf8)! + guard let value = String(data: try get(key), encoding: .utf8) else { + throw Error.unexpectedData + } + return value + } + + public func get(_ key: String) throws -> UUID { + guard let value = UUID(uuidString: try get(key)) else { + throw Error.unexpectedData + } + return value } public func get(_ key: String, decoder: JSONDecoder = JSONDecoder()) throws -> T where T: Decodable { @@ -70,6 +80,10 @@ public struct Keychain { try set(value.data(using: .utf8)!, for: key) } + public func set(_ uuid: UUID, for key: String) throws { + try set(uuid.uuidString, for: key) + } + public func set(_ value: T, for key: String, encoder: JSONEncoder = JSONEncoder()) throws where T: Encodable { try set(encoder.encode(value), for: key) } From b294163866195f0840a061a23b7eb4c46b91c038 Mon Sep 17 00:00:00 2001 From: Aleksey Zgurskiy Date: Mon, 3 Feb 2020 10:38:50 +0200 Subject: [PATCH 2/2] Update version --- keychain-kit.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/keychain-kit.xcodeproj/project.pbxproj b/keychain-kit.xcodeproj/project.pbxproj index f862347..0705aa5 100644 --- a/keychain-kit.xcodeproj/project.pbxproj +++ b/keychain-kit.xcodeproj/project.pbxproj @@ -302,7 +302,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 1.0.0; + MARKETING_VERSION = 1.1.0; PRODUCT_BUNDLE_IDENTIFIER = "com.mr-noone.keychain-kit"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -327,7 +327,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 1.0.0; + MARKETING_VERSION = 1.1.0; PRODUCT_BUNDLE_IDENTIFIER = "com.mr-noone.keychain-kit"; SKIP_INSTALL = YES; SWIFT_VERSION = 5.0;