From 0e4a4d5aef7c6dc54277bfb7877258802e41fc59 Mon Sep 17 00:00:00 2001 From: Suyeol Jeon Date: Sat, 24 Sep 2016 05:41:00 +0900 Subject: [PATCH] Add ImmutableMutable initializers --- ObjectMapper/Core/ImmutableMappble.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ObjectMapper/Core/ImmutableMappble.swift b/ObjectMapper/Core/ImmutableMappble.swift index c168cd15..af444ae9 100644 --- a/ObjectMapper/Core/ImmutableMappble.swift +++ b/ObjectMapper/Core/ImmutableMappble.swift @@ -152,6 +152,21 @@ public extension Map { } +public extension ImmutableMappable { + + /// Initializes object from a JSON String + public init(JSONString: String, context: MapContext? = nil) throws { + self = try Mapper(context: context).map(JSONString: JSONString) + } + + /// Initializes object from a JSON Dictionary + public init?(JSON: [String: Any], context: MapContext? = nil) throws { + self = try Mapper(context: context).map(JSON: JSON) + } + +} + + public extension Mapper where N: ImmutableMappable { public func map(JSON: [String: Any]) throws -> N {