From b24305e683d77dfe50c5e069e68516773cb3bdfd Mon Sep 17 00:00:00 2001 From: Tristan Himmelman Date: Fri, 24 Feb 2017 11:48:25 -0500 Subject: [PATCH] minor formatting updates --- Sources/ImmutableMappable.swift | 20 ++++++++------------ Sources/TransformOperators.swift | 4 ++-- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/Sources/ImmutableMappable.swift b/Sources/ImmutableMappable.swift index 9d33e4bf..ca5a3f0b 100644 --- a/Sources/ImmutableMappable.swift +++ b/Sources/ImmutableMappable.swift @@ -126,6 +126,7 @@ public extension Map { /// Returns a `[String: BaseMappable]` or throws an error. public func value(_ key: String, nested: Bool? = nil, delimiter: String = ".", file: StaticString = #file, function: StaticString = #function, line: UInt = #line) throws -> [String: T] { + let currentValue = self.currentValue(for: key, nested: nested, delimiter: delimiter) guard let jsonDictionary = currentValue as? [String: Any] else { throw MapError(key: key, currentValue: currentValue, reason: "Cannot cast to '[String: Any]'", file: file, function: function, line: line) @@ -139,6 +140,7 @@ public extension Map { /// Returns a `[String: BaseMappable]` using transform or throws an error. public func value(_ key: String, nested: Bool? = nil, delimiter: String = ".", using transform: Transform, file: StaticString = #file, function: StaticString = #function, line: UInt = #line) throws -> [String: Transform.Object] { + let currentValue = self.currentValue(for: key, nested: nested, delimiter: delimiter) guard let jsonDictionary = currentValue as? [String: Any] else { throw MapError(key: key, currentValue: currentValue, reason: "Cannot cast to '[String: Any]'", file: file, function: function, line: line) @@ -155,13 +157,11 @@ public extension Map { // MARK: [[BaseMappable]] /// Returns a `[[BaseMappable]]` or throws an error. - public func value(_ key: String, nested: Bool? = nil, delimiter: String = ".", - file: StaticString = #file, function: StaticString = #function, - line: UInt = #line) throws -> [[T]] { + public func value(_ key: String, nested: Bool? = nil, delimiter: String = ".", file: StaticString = #file, function: StaticString = #function, line: UInt = #line) throws -> [[T]] { + let currentValue = self.currentValue(for: key, nested: nested, delimiter: delimiter) guard let json2DArray = currentValue as? [[Any]] else { - throw MapError(key: key, currentValue: currentValue, reason: "Cannot cast to '[[Any]]'", file: file, - function: function, line: line) + throw MapError(key: key, currentValue: currentValue, reason: "Cannot cast to '[[Any]]'", file: file, function: function, line: line) } return try json2DArray.map { jsonArray in try jsonArray.map { jsonObject -> T in @@ -171,10 +171,8 @@ public extension Map { } /// Returns a `[[BaseMappable]]` using transform or throws an error. - public func value(_ key: String, nested: Bool? = nil, delimiter: String = ".", - using transform: Transform, file: StaticString = #file, - function: StaticString = #function, - line: UInt = #line) throws -> [[Transform.Object]] { + public func value(_ key: String, nested: Bool? = nil, delimiter: String = ".", using transform: Transform, file: StaticString = #file, function: StaticString = #function, line: UInt = #line) throws -> [[Transform.Object]] { + let currentValue = self.currentValue(for: key, nested: nested, delimiter: delimiter) guard let json2DArray = currentValue as? [[Any]] else { throw MapError(key: key, currentValue: currentValue, reason: "Cannot cast to '[[Any]]'", @@ -183,9 +181,7 @@ public extension Map { return try json2DArray.enumerated().map { i, jsonArray in try jsonArray.enumerated().map { j, json -> Transform.Object in guard let object = transform.transformFromJSON(json) else { - throw MapError(key: "\(key)[\(i)][\(j)]", currentValue: json, - reason: "Cannot transform to '\(Transform.Object.self)' using \(transform)", file: file, - function: function, line: line) + throw MapError(key: "\(key)[\(i)][\(j)]", currentValue: json, reason: "Cannot transform to '\(Transform.Object.self)' using \(transform)", file: file, function: function, line: line) } return object } diff --git a/Sources/TransformOperators.swift b/Sources/TransformOperators.swift index 3659536c..b08a8b5e 100644 --- a/Sources/TransformOperators.swift +++ b/Sources/TransformOperators.swift @@ -474,7 +474,7 @@ public func >>> (left: [[Transform.Object]], right: (M } } -/// Optional array of objects with transform +/// Optional array of array of objects with transform public func <- (left: inout [[Transform.Object]]?, right: (Map, Transform)) { let (map, transform) = right switch map.mappingType { @@ -502,7 +502,7 @@ public func >>> (left: [[Transform.Object]]?, right: ( } -/// Implicitly unwrapped Optional array of objects with transform +/// Implicitly unwrapped Optional array of array of objects with transform public func <- (left: inout [[Transform.Object]]!, right: (Map, Transform)) { let (map, transform) = right switch map.mappingType {