From 4133a623c4dc1d1ba9a107cc9bbee954ada16c6a Mon Sep 17 00:00:00 2001 From: Mike Pollard Date: Tue, 22 Feb 2022 12:31:48 +0000 Subject: [PATCH] Add support for decoding Date type --- Sources/AnyCodable/AnyDecodable.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/AnyCodable/AnyDecodable.swift b/Sources/AnyCodable/AnyDecodable.swift index 9b42228..7138d38 100644 --- a/Sources/AnyCodable/AnyDecodable.swift +++ b/Sources/AnyCodable/AnyDecodable.swift @@ -67,6 +67,8 @@ extension _AnyDecodable { self.init(double) } else if let string = try? container.decode(String.self) { self.init(string) + } else if let date = try? container.decode(Date.self) { + self.init(date) } else if let array = try? container.decode([AnyDecodable].self) { self.init(array.map { $0.value }) } else if let dictionary = try? container.decode([String: AnyDecodable].self) { @@ -112,6 +114,8 @@ extension AnyDecodable: Equatable { return lhs == rhs case let (lhs as String, rhs as String): return lhs == rhs + case let (lhs as Date, rhs as Date): + return lhs == rhs case let (lhs as [String: AnyDecodable], rhs as [String: AnyDecodable]): return lhs == rhs case let (lhs as [AnyDecodable], rhs as [AnyDecodable]): @@ -177,6 +181,8 @@ extension AnyDecodable: Hashable { hasher.combine(value) case let value as String: hasher.combine(value) + case let value as Date: + hasher.combine(value) case let value as [String: AnyDecodable]: hasher.combine(value) case let value as [AnyDecodable]: