From 071cb16870dfc96e22c9c8f575ad31cba26ff2e2 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 24 May 2022 12:07:03 -0500 Subject: [PATCH] ensure context exists for JSONDecoder within extension method Signed-off-by: Matt Bruce --- MVMCore/MVMCore/Models/Extensions/Decoder.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MVMCore/MVMCore/Models/Extensions/Decoder.swift b/MVMCore/MVMCore/Models/Extensions/Decoder.swift index e4b5863..ca66508 100644 --- a/MVMCore/MVMCore/Models/Extensions/Decoder.swift +++ b/MVMCore/MVMCore/Models/Extensions/Decoder.swift @@ -28,6 +28,9 @@ extension Data { extension JSONDecoder { /// Decodes a top-level value of the given type from the given JSON representation, and adds the delegate object if provided. func decode(_ type: T.Type, from data: Data, delegateObject: DelegateObject?) throws -> T where T : Decodable { + if context == nil { + add(value: DecodingContext(), for: .contextKey) + } if let delegateObject = delegateObject { add(value: delegateObject, for: .delegateObjectKey) }