Skip to content

Commit 5a50e25

Browse files
temp
1 parent 8749cc6 commit 5a50e25

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Sources/DynamicCodable/DynamicCodableDecoder.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// Copyright © 2021 Mochi Development, Inc. All rights reserved.
77
//
88

9+
import Foundation
10+
911
/// `DynamicCodableDecoder` facilitates the decoding of [DynamicCodable](x-source-tag://DynamicCodable) representations into semantic `Decodable` types.
1012
/// - Tag: DynamicCodableDecoder
1113
open class DynamicCodableDecoder {
@@ -171,6 +173,9 @@ extension DynamicCodableDecoder.Decoder: Swift.Decoder {
171173
is Primitive.Bool.Type,
172174
is Primitive.String.Type,
173175
is Primitive.Empty.Type: return try value.unwrap { throw createTypeMismatchError(type: T.self) }
176+
// Special Cases
177+
case is Date.Type: return try unwrapDate() as! T
178+
case is NSDate.Type: return try unwrapDate() as! T
174179
// Decodable Types
175180
default: return try T(from: self)
176181
}
@@ -291,6 +296,11 @@ extension DynamicCodableDecoder.Decoder: Swift.Decoder {
291296
}
292297
}
293298

299+
@inline(__always)
300+
private func unwrapDate() throws -> Date {
301+
throw createTypeMismatchError(type: Date.self)
302+
}
303+
294304
private func createTypeMismatchError(type: Any.Type) -> DecodingError {
295305
DecodingError.typeMismatch(
296306
type,

0 commit comments

Comments
 (0)