From e1d816c69e49c4a9f4007967cfba2d67c67255cf Mon Sep 17 00:00:00 2001 From: Dariusz Rybicki <dariusz@elixxir.io> Date: Wed, 20 Jul 2022 12:07:42 +0100 Subject: [PATCH] Add LoadReceptionIdentity functor --- .../LoadReceptionIdentity.swift | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Sources/ElixxirDAppsSDK/LoadReceptionIdentity.swift diff --git a/Sources/ElixxirDAppsSDK/LoadReceptionIdentity.swift b/Sources/ElixxirDAppsSDK/LoadReceptionIdentity.swift new file mode 100644 index 00000000..eeb1c832 --- /dev/null +++ b/Sources/ElixxirDAppsSDK/LoadReceptionIdentity.swift @@ -0,0 +1,33 @@ +import Bindings +import XCTestDynamicOverlay + +public struct LoadReceptionIdentity { + public var run: (String, Int) throws -> Data + + public func callAsFunction( + key: String, + cmixId: Int + ) throws -> Data { + try run(key, cmixId) + } +} + +extension LoadReceptionIdentity { + public static let live = LoadReceptionIdentity { key, cmixId in + var error: NSError? + let data = BindingsLoadReceptionIdentity(key, cmixId, &error) + if let error = error { + throw error + } + guard let data = data else { + fatalError("BindingsLoadReceptionIdentity returned `nil` without providing error") + } + return data + } +} + +extension LoadReceptionIdentity { + public static let unimplemented = LoadReceptionIdentity( + run: XCTUnimplemented("\(Self.self)") + ) +} -- GitLab