From fabf582ad9ba6618283229e841dc557ea9daad08 Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 3 Jul 2019 15:41:13 +0100 Subject: [PATCH] Enabling pattern matching on ECError --- Sources/CryptorECC/ECError.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sources/CryptorECC/ECError.swift b/Sources/CryptorECC/ECError.swift index 605d391..cffefc7 100644 --- a/Sources/CryptorECC/ECError.swift +++ b/Sources/CryptorECC/ECError.swift @@ -69,4 +69,12 @@ public struct ECError: Error, Equatable { public static func == (lhs: ECError, rhs: ECError) -> Bool { return lhs.internalError == rhs.internalError } + + /// Function to enable pattern matching against generic Errors. + public static func ~= (lhs: ECError, rhs: Error) -> Bool { + guard let rhs = rhs as? ECError else { + return false + } + return lhs == rhs + } }