diff --git a/MVMCore/MVMCore/Models/Extensions/Decoder+UserInfo.swift b/MVMCore/MVMCore/Models/Extensions/Decoder+UserInfo.swift index d8ffda1..686b241 100644 --- a/MVMCore/MVMCore/Models/Extensions/Decoder+UserInfo.swift +++ b/MVMCore/MVMCore/Models/Extensions/Decoder+UserInfo.swift @@ -9,15 +9,15 @@ import Foundation extension CodingUserInfoKey { - internal static let delegateObjectKey = CodingUserInfoKey(rawValue: "delegateObject")! - internal static let contextKey = CodingUserInfoKey(rawValue: "context")! + public static let delegateObjectKey = CodingUserInfoKey(rawValue: "delegateObject")! + public static let contextKey = CodingUserInfoKey(rawValue: "context")! } // MARK: - DelegateObject public extension JSONDecoder { /// Adds a delegate object to the decoder for use in the model initializers. - func add(value: Any, for key: CodingUserInfoKey) { - userInfo.updateValue(value, forKey: key) + func add(delegateObject: T) { + add(value: delegateObject, for: .delegateObjectKey) } } @@ -89,11 +89,15 @@ extension Decoder { } extension JSONDecoder { + /// Adds a key/value to the decoder for use in the model initializers. + func add(value: Any, for key: CodingUserInfoKey) { + userInfo.updateValue(value, forKey: key) + } /// Helper method to initialize a JSONDecoder /// - Parameter delegateObject: Delegate Object /// - Returns: JSONDecoder - public class func create(delegateObject: DelegateObject? = nil) -> JSONDecoder { + public class func create(with delegateObject: DelegateObject? = nil) -> JSONDecoder { let decoder = JSONDecoder() decoder.add(value: DecodingContext(), for: .contextKey) if let delegateObject = delegateObject { diff --git a/MVMCore/MVMCore/Models/Extensions/Decoder.swift b/MVMCore/MVMCore/Models/Extensions/Decoder.swift index 0c0311b..e4b5863 100644 --- a/MVMCore/MVMCore/Models/Extensions/Decoder.swift +++ b/MVMCore/MVMCore/Models/Extensions/Decoder.swift @@ -52,7 +52,7 @@ extension Decodable { public static func decode(jsonDict: [String: Any], delegateObject: DelegateObject? = nil) throws -> Self { let jsonData = try JSONSerialization.data(withJSONObject: jsonDict) do { - let decoder = JSONDecoder.create(delegateObject: delegateObject) + let decoder = JSONDecoder.create(with: delegateObject) return try jsonData.decode(using: decoder) } catch { throw JSONError.other(error: error)