From bed2ff971f64f3aa1aa31a3448155f96a31afecd Mon Sep 17 00:00:00 2001 From: Giorgos Charitakis Date: Thu, 7 Jun 2018 17:30:53 +0300 Subject: [PATCH 1/4] Added support for Swift 4.2 and Xcode 10 --- Sources/EnumOperators.swift | 6 ++++ Sources/FromJSON.swift | 16 ++++++++- Sources/ImmutableMappable.swift | 4 +++ Sources/IntegerOperators.swift | 4 +++ Sources/Map.swift | 4 +++ Sources/Mapper.swift | 8 +++++ Sources/Operators.swift | 14 ++++++++ Sources/TransformOperators.swift | 60 ++++++++++++++++++++++++++++++++ 8 files changed, 115 insertions(+), 1 deletion(-) diff --git a/Sources/EnumOperators.swift b/Sources/EnumOperators.swift index 5a1a667a..21ae5f04 100644 --- a/Sources/EnumOperators.swift +++ b/Sources/EnumOperators.swift @@ -31,10 +31,12 @@ public func >>> (left: T?, right: Map) { } +#if !swift(>=4.2) /// Implicitly Unwrapped Optional Object of Raw Representable type public func <- (left: inout T!, right: Map) { left <- (right, EnumTransform()) } +#endif // MARK:- Arrays of Raw Representable type @@ -58,10 +60,12 @@ public func >>> (left: [T]?, right: Map) { } +#if !swift(>=4.2) /// Array of Raw Representable object public func <- (left: inout [T]!, right: Map) { left <- (right, EnumTransform()) } +#endif // MARK:- Dictionaries of Raw Representable type @@ -85,7 +89,9 @@ public func >>> (left: [String: T]?, right: Map) { } +#if !swift(>=4.2) /// Dictionary of Raw Representable object public func <- (left: inout [String: T]!, right: Map) { left <- (right, EnumTransform()) } +#endif diff --git a/Sources/FromJSON.swift b/Sources/FromJSON.swift index 952b42b4..4959b093 100755 --- a/Sources/FromJSON.swift +++ b/Sources/FromJSON.swift @@ -40,10 +40,12 @@ internal final class FromJSON { field = object } + #if !swift(>=4.2) /// Implicitly unwrapped optional basic type class func optionalBasicType(_ field: inout FieldType!, object: FieldType?) { field = object } + #endif /// Mappable object class func object(_ field: inout N, map: Map) { @@ -64,6 +66,7 @@ internal final class FromJSON { } } + #if !swift(>=4.2) /// Implicitly unwrapped Optional Mappable Object class func optionalObject(_ field: inout N!, map: Map) { if let f = field , map.toObject && map.currentValue != nil { @@ -72,6 +75,7 @@ internal final class FromJSON { field = Mapper(context: map.context).map(JSONObject: map.currentValue) } } + #endif /// mappable object array class func objectArray(_ field: inout Array, map: Map) { @@ -90,6 +94,7 @@ internal final class FromJSON { } } + #if !swift(>=4.2) /// Implicitly unwrapped optional mappable object array class func optionalObjectArray(_ field: inout Array!, map: Map) { if let objects: Array = Mapper(context: map.context).mapArray(JSONObject: map.currentValue) { @@ -98,6 +103,7 @@ internal final class FromJSON { field = nil } } + #endif /// mappable object array class func twoDimensionalObjectArray(_ field: inout Array>, map: Map) { @@ -111,10 +117,12 @@ internal final class FromJSON { field = Mapper(context: map.context).mapArrayOfArrays(JSONObject: map.currentValue) } + #if !swift(>=4.2) /// Implicitly unwrapped optional 2 dimentional mappable object array class func optionalTwoDimensionalObjectArray(_ field: inout Array>!, map: Map) { field = Mapper(context: map.context).mapArrayOfArrays(JSONObject: map.currentValue) } + #endif /// Dctionary containing Mappable objects class func objectDictionary(_ field: inout Dictionary, map: Map) { @@ -136,6 +144,7 @@ internal final class FromJSON { } } + #if !swift(>=4.2) /// Implicitly unwrapped Dictionary containing Mappable objects class func optionalObjectDictionary(_ field: inout Dictionary!, map: Map) { if let f = field , map.toObject && map.currentValue != nil { @@ -144,6 +153,7 @@ internal final class FromJSON { field = Mapper(context: map.context).mapDictionary(JSONObject: map.currentValue) } } + #endif /// Dictionary containing Array of Mappable objects class func objectDictionaryOfArrays(_ field: inout Dictionary, map: Map) { @@ -157,10 +167,12 @@ internal final class FromJSON { field = Mapper(context: map.context).mapDictionaryOfArrays(JSONObject: map.currentValue) } + #if !swift(>=4.2) /// Implicitly unwrapped Dictionary containing Array of Mappable objects class func optionalObjectDictionaryOfArrays(_ field: inout Dictionary!, map: Map) { field = Mapper(context: map.context).mapDictionaryOfArrays(JSONObject: map.currentValue) } + #endif /// mappable object Set class func objectSet(_ field: inout Set, map: Map) { @@ -174,8 +186,10 @@ internal final class FromJSON { field = Mapper(context: map.context).mapSet(JSONObject: map.currentValue) } + #if !swift(>=4.2) /// Implicitly unwrapped optional mappable object array class func optionalObjectSet(_ field: inout Set!, map: Map) { field = Mapper(context: map.context).mapSet(JSONObject: map.currentValue) - } + } + #endif } diff --git a/Sources/ImmutableMappable.swift b/Sources/ImmutableMappable.swift index 589ea107..27b6315c 100644 --- a/Sources/ImmutableMappable.swift +++ b/Sources/ImmutableMappable.swift @@ -214,7 +214,11 @@ public extension Mapper where N: ImmutableMappable { // MARK: Array mapping functions public func mapArray(JSONArray: [[String: Any]]) throws -> [N] { + #if swift(>=4.1) return try JSONArray.compactMap(mapOrFail) + #else + return try JSONArray.flatMap(mapOrFail) + #endif } public func mapArray(JSONString: String) throws -> [N] { diff --git a/Sources/IntegerOperators.swift b/Sources/IntegerOperators.swift index a4191e60..21d1015b 100644 --- a/Sources/IntegerOperators.swift +++ b/Sources/IntegerOperators.swift @@ -34,6 +34,7 @@ public func <- (left: inout T?, right: Map) { } } +#if !swift(>=4.2) /// ImplicitlyUnwrappedOptional SignedInteger mapping public func <- (left: inout T!, right: Map) { switch right.mappingType { @@ -45,6 +46,7 @@ public func <- (left: inout T!, right: Map) { default: () } } +#endif // MARK: - Unsigned Integer @@ -74,6 +76,7 @@ public func <- (left: inout T?, right: Map) { } } +#if !swift(>=4.2) /// ImplicitlyUnwrappedOptional UnsignedInteger mapping public func <- (left: inout T!, right: Map) { switch right.mappingType { @@ -85,6 +88,7 @@ public func <- (left: inout T!, right: Map) { default: () } } +#endif // MARK: - Casting Utils diff --git a/Sources/Map.swift b/Sources/Map.swift index d1ea3462..cec8925a 100644 --- a/Sources/Map.swift +++ b/Sources/Map.swift @@ -131,7 +131,11 @@ public final class Map { } } else if value == nil && T.self == [Float].self { if let v = currentValue as? [Double] { + #if swift(>=4.1) return v.compactMap{ Float($0) } as? T + #else + return v.flatMap{ Float($0) } as? T + #endif } } else if value == nil && T.self == [String:Float].self { if let v = currentValue as? [String:Double] { diff --git a/Sources/Mapper.swift b/Sources/Mapper.swift index 134d9f4e..ffbae4f4 100755 --- a/Sources/Mapper.swift +++ b/Sources/Mapper.swift @@ -159,7 +159,11 @@ public final class Mapper { /// Maps an array of JSON dictionary to an array of Mappable objects public func mapArray(JSONArray: [[String: Any]]) -> [N] { // map every element in JSON array to type N + #if swift(>=4.1) + let result = JSONArray.compactMap(map) + #else let result = JSONArray.flatMap(map) + #endif return result } @@ -425,7 +429,11 @@ extension Mapper where N: Hashable { /// Maps an Set of JSON dictionary to an array of Mappable objects public func mapSet(JSONArray: [[String: Any]]) -> Set { // map every element in JSON array to type N + #if swift(>=4.1) return Set(JSONArray.compactMap(map)) + #else + return Set(JSONArray.flatMap(map)) + #endif } ///Maps a Set of Objects to a Set of JSON dictionaries [[String : Any]] diff --git a/Sources/Operators.swift b/Sources/Operators.swift index eb497350..605993c4 100755 --- a/Sources/Operators.swift +++ b/Sources/Operators.swift @@ -76,6 +76,7 @@ public func >>> (left: T?, right: Map) { } +#if !swift(>=4.2) /// Implicitly unwrapped optional object of basic type public func <- (left: inout T!, right: Map) { switch right.mappingType { @@ -86,6 +87,7 @@ public func <- (left: inout T!, right: Map) { default: () } } +#endif // MARK:- Mappable Objects - @@ -124,6 +126,7 @@ public func >>> (left: T?, right: Map) { } +#if !swift(>=4.2) /// Implicitly unwrapped optional Mappable objects public func <- (left: inout T!, right: Map) { switch right.mappingType { @@ -134,6 +137,7 @@ public func <- (left: inout T!, right: Map) { default: () } } +#endif // MARK:- Dictionary of Mappable objects - Dictionary @@ -173,6 +177,7 @@ public func >>> (left: Dictionary?, right: Map) { } +#if !swift(>=4.2) /// Implicitly unwrapped Optional Dictionary of Mappable object public func <- (left: inout Dictionary!, right: Map) { switch right.mappingType { @@ -183,6 +188,7 @@ public func <- (left: inout Dictionary!, right: Map) default: () } } +#endif /// Dictionary of Mappable objects public func <- (left: inout Dictionary, right: Map) { @@ -219,6 +225,7 @@ public func >>> (left: Dictionary?, right: Map) { } +#if !swift(>=4.2) /// Implicitly unwrapped Optional Dictionary of Mappable object public func <- (left: inout Dictionary!, right: Map) { switch right.mappingType { @@ -229,6 +236,7 @@ public func <- (left: inout Dictionary!, right: Ma default: () } } +#endif // MARK:- Array of Mappable objects - Array @@ -267,6 +275,7 @@ public func >>> (left: Array?, right: Map) { } +#if !swift(>=4.2) /// Implicitly unwrapped Optional array of Mappable objects public func <- (left: inout Array!, right: Map) { switch right.mappingType { @@ -277,6 +286,7 @@ public func <- (left: inout Array!, right: Map) { default: () } } +#endif // MARK:- Array of Array of Mappable objects - Array> @@ -316,6 +326,7 @@ public func >>> (left: Array>?, right: Map) { } +#if !swift(>=4.2) /// Implicitly unwrapped Optional array of Mappable objects public func <- (left: inout Array>!, right: Map) { switch right.mappingType { @@ -326,6 +337,7 @@ public func <- (left: inout Array>!, right: Map) { default: () } } +#endif // MARK:- Set of Mappable objects - Set @@ -365,6 +377,7 @@ public func >>> (left: Set?, right: Map) { } +#if !swift(>=4.2) /// Implicitly unwrapped Optional Set of Mappable objects public func <- (left: inout Set!, right: Map) { switch right.mappingType { @@ -375,3 +388,4 @@ public func <- (left: inout Set!, right: Map) { default: () } } +#endif diff --git a/Sources/TransformOperators.swift b/Sources/TransformOperators.swift index a0208b56..a2d60689 100644 --- a/Sources/TransformOperators.swift +++ b/Sources/TransformOperators.swift @@ -54,6 +54,7 @@ public func >>> (left: Transform.Object?, right: (Map, } +#if !swift(>=4.2) /// Implicitly unwrapped optional object of basic type with Transform public func <- (left: inout Transform.Object!, right: (Map, Transform)) { let (map, transform) = right @@ -66,6 +67,7 @@ public func <- (left: inout Transform.Object!, right: default: () } } +#endif /// Array of Basic type with Transform public func <- (left: inout [Transform.Object], right: (Map, Transform)) { @@ -111,6 +113,7 @@ public func >>> (left: [Transform.Object]?, right: (Ma } +#if !swift(>=4.2) /// Implicitly unwrapped optional array of Basic type with Transform public func <- (left: inout [Transform.Object]!, right: (Map, Transform)) { let (map, transform) = right @@ -123,6 +126,7 @@ public func <- (left: inout [Transform.Object]!, right default: () } } +#endif /// Dictionary of Basic type with Transform public func <- (left: inout [String: Transform.Object], right: (Map, Transform)) { @@ -168,6 +172,7 @@ public func >>> (left: [String: Transform.Object]?, ri } +#if !swift(>=4.2) /// Implicitly unwrapped optional dictionary of Basic type with Transform public func <- (left: inout [String: Transform.Object]!, right: (Map, Transform)) { let (map, transform) = right @@ -180,6 +185,7 @@ public func <- (left: inout [String: Transform.Object] default: () } } +#endif // MARK:- Transforms of Mappable Objects - @@ -227,6 +233,7 @@ public func >>> (left: Transform.Object?, right: (Map, } +#if !swift(>=4.2) /// Implicitly unwrapped optional Mappable objects that have transforms public func <- (left: inout Transform.Object!, right: (Map, Transform)) where Transform.Object: BaseMappable { let (map, transform) = right @@ -239,6 +246,7 @@ public func <- (left: inout Transform.Object!, right: default: () } } +#endif // MARK:- Dictionary of Mappable objects with a transform - Dictionary @@ -284,6 +292,7 @@ public func >>> (left: Dictionary=4.2) /// Implicitly unwrapped Optional Dictionary of Mappable object with a transform public func <- (left: inout Dictionary!, right: (Map, Transform)) where Transform.Object: BaseMappable { let (map, transform) = right @@ -294,6 +303,7 @@ public func <- (left: inout Dictionary>> right } } +#endif /// Dictionary of Mappable objects with a transform public func <- (left: inout Dictionary, right: (Map, Transform)) where Transform.Object: BaseMappable { @@ -367,6 +377,7 @@ public func >>> (left: Dictionary=4.2) /// Implicitly unwrapped Optional Dictionary of Mappable object with a transform public func <- (left: inout Dictionary!, right: (Map, Transform)) where Transform.Object: BaseMappable { let (map, transform) = right @@ -387,6 +398,7 @@ public func <- (left: inout Dictionary>> right } } +#endif // MARK:- Array of Mappable objects with transforms - Array @@ -435,6 +447,7 @@ public func >>> (left: Array?, right } +#if !swift(>=4.2) /// Implicitly unwrapped Optional array of Mappable objects public func <- (left: inout Array!, right: (Map, Transform)) where Transform.Object: BaseMappable { let (map, transform) = right @@ -447,6 +460,7 @@ public func <- (left: inout Array!, default: () } } +#endif // MARK:- Array of Array of objects - Array>> with transforms @@ -458,9 +472,15 @@ public func <- (left: inout [[Transform.Object]], righ left >>> right case .fromJSON where map.isKeyPresent: guard let original2DArray = map.currentValue as? [[Any]] else { break } + #if swift(>=4.1) let transformed2DArray = original2DArray.compactMap { values in fromJSONArrayWithTransform(values as Any?, transform: transform) } + #else + let transformed2DArray = original2DArray.flatMap { values in + fromJSONArrayWithTransform(values as Any?, transform: transform) + } + #endif FromJSON.basicType(&left, object: transformed2DArray) default: break @@ -470,9 +490,15 @@ public func <- (left: inout [[Transform.Object]], righ public func >>> (left: [[Transform.Object]], right: (Map, Transform)) { let (map, transform) = right if map.mappingType == .toJSON{ + #if swift(>=4.1) let transformed2DArray = left.compactMap { values in toJSONArrayWithTransform(values, transform: transform) } + #else + let transformed2DArray = left.flatMap { values in + toJSONArrayWithTransform(values, transform: transform) + } + #endif ToJSON.basicType(transformed2DArray, map: map) } } @@ -485,9 +511,15 @@ public func <- (left: inout [[Transform.Object]]?, rig left >>> right case .fromJSON where map.isKeyPresent: guard let original2DArray = map.currentValue as? [[Any]] else { break } + #if swift(>=4.1) let transformed2DArray = original2DArray.compactMap { values in fromJSONArrayWithTransform(values as Any?, transform: transform) } + #else + let transformed2DArray = original2DArray.flatMap { values in + fromJSONArrayWithTransform(values as Any?, transform: transform) + } + #endif FromJSON.optionalBasicType(&left, object: transformed2DArray) default: break @@ -497,14 +529,21 @@ public func <- (left: inout [[Transform.Object]]?, rig public func >>> (left: [[Transform.Object]]?, right: (Map, Transform)) { let (map, transform) = right if map.mappingType == .toJSON { + #if swift(>=4.1) let transformed2DArray = left?.compactMap { values in toJSONArrayWithTransform(values, transform: transform) } + #else + let transformed2DArray = left?.flatMap { values in + toJSONArrayWithTransform(values, transform: transform) + } + #endif ToJSON.optionalBasicType(transformed2DArray, map: map) } } +#if !swift(>=4.2) /// Implicitly unwrapped Optional array of array of objects with transform public func <- (left: inout [[Transform.Object]]!, right: (Map, Transform)) { let (map, transform) = right @@ -513,14 +552,21 @@ public func <- (left: inout [[Transform.Object]]!, rig left >>> right case .fromJSON where map.isKeyPresent: guard let original2DArray = map.currentValue as? [[Any]] else { break } + #if swift(>=4.1) let transformed2DArray = original2DArray.compactMap { values in fromJSONArrayWithTransform(values as Any?, transform: transform) } + #else + let transformed2DArray = original2DArray.flatMap { values in + fromJSONArrayWithTransform(values as Any?, transform: transform) + } + #endif FromJSON.optionalBasicType(&left, object: transformed2DArray) default: break } } +#endif // MARK:- Set of Mappable objects with a transform - Set @@ -572,6 +618,7 @@ public func >>> (left: Set?, right: } +#if !swift(>=4.2) /// Implicitly unwrapped Optional set of Mappable objects with transform public func <- (left: inout Set!, right: (Map, Transform)) where Transform.Object: BaseMappable { let (map, transform) = right @@ -585,13 +632,20 @@ public func <- (left: inout Set!, ri default: () } } +#endif private func fromJSONArrayWithTransform(_ input: Any?, transform: Transform) -> [Transform.Object]? { if let values = input as? [Any] { + #if swift(>=4.1) + return values.compactMap { value in + return transform.transformFromJSON(value) + } + #else return values.flatMap { value in return transform.transformFromJSON(value) } + #endif } else { return nil } @@ -608,9 +662,15 @@ private func fromJSONDictionaryWithTransform(_ input: } private func toJSONArrayWithTransform(_ input: [Transform.Object]?, transform: Transform) -> [Transform.JSON]? { + #if swift(>=4.1) + return input?.compactMap { value in + return transform.transformToJSON(value) + } + #else return input?.flatMap { value in return transform.transformToJSON(value) } + #endif } private func toJSONDictionaryWithTransform(_ input: [String: Transform.Object]?, transform: Transform) -> [String: Transform.JSON]? { From 2ea5aec9f0657f10cdb52082a645a0c3aa69d27c Mon Sep 17 00:00:00 2001 From: Giorgos Charitakis Date: Fri, 8 Jun 2018 11:57:25 +0300 Subject: [PATCH 2/4] Changed Swift version to 4.2 --- .swift-version | 2 +- ObjectMapper.podspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.swift-version b/.swift-version index 5186d070..bf77d549 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -4.0 +4.2 diff --git a/ObjectMapper.podspec b/ObjectMapper.podspec index cd4a7e03..7d8f40e4 100644 --- a/ObjectMapper.podspec +++ b/ObjectMapper.podspec @@ -12,7 +12,7 @@ Pod::Spec.new do |s| s.osx.deployment_target = '10.9' s.tvos.deployment_target = '9.0' - s.swift_version = '4.0' + s.swift_version = '4.2' s.requires_arc = true s.source_files = 'Sources/**/*.swift' From c31a112145d24541800a103ba4fd47500c6628c0 Mon Sep 17 00:00:00 2001 From: Giorgos Charitakis Date: Thu, 14 Jun 2018 11:46:55 +0300 Subject: [PATCH 3/4] Revert "Changed Swift version to 4.2" This reverts commit 2ea5aec9f0657f10cdb52082a645a0c3aa69d27c. --- .swift-version | 2 +- ObjectMapper.podspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.swift-version b/.swift-version index bf77d549..5186d070 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -4.2 +4.0 diff --git a/ObjectMapper.podspec b/ObjectMapper.podspec index 7d8f40e4..cd4a7e03 100644 --- a/ObjectMapper.podspec +++ b/ObjectMapper.podspec @@ -12,7 +12,7 @@ Pod::Spec.new do |s| s.osx.deployment_target = '10.9' s.tvos.deployment_target = '9.0' - s.swift_version = '4.2' + s.swift_version = '4.0' s.requires_arc = true s.source_files = 'Sources/**/*.swift' From 5985794dc23929ed2de4b4394bfadd29fff32bb4 Mon Sep 17 00:00:00 2001 From: Giorgos Charitakis Date: Thu, 14 Jun 2018 12:37:24 +0300 Subject: [PATCH 4/4] Change compiler directives, in IUO overloads, to target the Swift 4.1 compiler and below --- Sources/EnumOperators.swift | 9 ++++++--- Sources/FromJSON.swift | 21 ++++++++++++++------- Sources/IntegerOperators.swift | 6 ++++-- Sources/Operators.swift | 21 ++++++++++++++------- Sources/TransformOperators.swift | 27 ++++++++++++++++++--------- 5 files changed, 56 insertions(+), 28 deletions(-) diff --git a/Sources/EnumOperators.swift b/Sources/EnumOperators.swift index 21ae5f04..e4b3a38d 100644 --- a/Sources/EnumOperators.swift +++ b/Sources/EnumOperators.swift @@ -31,7 +31,8 @@ public func >>> (left: T?, right: Map) { } -#if !swift(>=4.2) +// Code targeting the Swift 4.1 compiler and below. +#if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// Implicitly Unwrapped Optional Object of Raw Representable type public func <- (left: inout T!, right: Map) { left <- (right, EnumTransform()) @@ -60,7 +61,8 @@ public func >>> (left: [T]?, right: Map) { } -#if !swift(>=4.2) +// Code targeting the Swift 4.1 compiler and below. +#if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// Array of Raw Representable object public func <- (left: inout [T]!, right: Map) { left <- (right, EnumTransform()) @@ -89,7 +91,8 @@ public func >>> (left: [String: T]?, right: Map) { } -#if !swift(>=4.2) +// Code targeting the Swift 4.1 compiler and below. +#if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// Dictionary of Raw Representable object public func <- (left: inout [String: T]!, right: Map) { left <- (right, EnumTransform()) diff --git a/Sources/FromJSON.swift b/Sources/FromJSON.swift index 4959b093..c5a28983 100755 --- a/Sources/FromJSON.swift +++ b/Sources/FromJSON.swift @@ -40,7 +40,8 @@ internal final class FromJSON { field = object } - #if !swift(>=4.2) + // Code targeting the Swift 4.1 compiler and below. + #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// Implicitly unwrapped optional basic type class func optionalBasicType(_ field: inout FieldType!, object: FieldType?) { field = object @@ -66,7 +67,8 @@ internal final class FromJSON { } } - #if !swift(>=4.2) + // Code targeting the Swift 4.1 compiler and below. + #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// Implicitly unwrapped Optional Mappable Object class func optionalObject(_ field: inout N!, map: Map) { if let f = field , map.toObject && map.currentValue != nil { @@ -94,7 +96,8 @@ internal final class FromJSON { } } - #if !swift(>=4.2) + // Code targeting the Swift 4.1 compiler and below. + #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// Implicitly unwrapped optional mappable object array class func optionalObjectArray(_ field: inout Array!, map: Map) { if let objects: Array = Mapper(context: map.context).mapArray(JSONObject: map.currentValue) { @@ -117,7 +120,8 @@ internal final class FromJSON { field = Mapper(context: map.context).mapArrayOfArrays(JSONObject: map.currentValue) } - #if !swift(>=4.2) + // Code targeting the Swift 4.1 compiler and below. + #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// Implicitly unwrapped optional 2 dimentional mappable object array class func optionalTwoDimensionalObjectArray(_ field: inout Array>!, map: Map) { field = Mapper(context: map.context).mapArrayOfArrays(JSONObject: map.currentValue) @@ -144,7 +148,8 @@ internal final class FromJSON { } } - #if !swift(>=4.2) + // Code targeting the Swift 4.1 compiler and below. + #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// Implicitly unwrapped Dictionary containing Mappable objects class func optionalObjectDictionary(_ field: inout Dictionary!, map: Map) { if let f = field , map.toObject && map.currentValue != nil { @@ -167,7 +172,8 @@ internal final class FromJSON { field = Mapper(context: map.context).mapDictionaryOfArrays(JSONObject: map.currentValue) } - #if !swift(>=4.2) + // Code targeting the Swift 4.1 compiler and below. + #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// Implicitly unwrapped Dictionary containing Array of Mappable objects class func optionalObjectDictionaryOfArrays(_ field: inout Dictionary!, map: Map) { field = Mapper(context: map.context).mapDictionaryOfArrays(JSONObject: map.currentValue) @@ -186,7 +192,8 @@ internal final class FromJSON { field = Mapper(context: map.context).mapSet(JSONObject: map.currentValue) } - #if !swift(>=4.2) + // Code targeting the Swift 4.1 compiler and below. + #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// Implicitly unwrapped optional mappable object array class func optionalObjectSet(_ field: inout Set!, map: Map) { field = Mapper(context: map.context).mapSet(JSONObject: map.currentValue) diff --git a/Sources/IntegerOperators.swift b/Sources/IntegerOperators.swift index 21d1015b..cd80334b 100644 --- a/Sources/IntegerOperators.swift +++ b/Sources/IntegerOperators.swift @@ -34,7 +34,8 @@ public func <- (left: inout T?, right: Map) { } } -#if !swift(>=4.2) +// Code targeting the Swift 4.1 compiler and below. +#if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// ImplicitlyUnwrappedOptional SignedInteger mapping public func <- (left: inout T!, right: Map) { switch right.mappingType { @@ -76,7 +77,8 @@ public func <- (left: inout T?, right: Map) { } } -#if !swift(>=4.2) +// Code targeting the Swift 4.1 compiler and below. +#if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// ImplicitlyUnwrappedOptional UnsignedInteger mapping public func <- (left: inout T!, right: Map) { switch right.mappingType { diff --git a/Sources/Operators.swift b/Sources/Operators.swift index 605993c4..30c2f120 100755 --- a/Sources/Operators.swift +++ b/Sources/Operators.swift @@ -76,7 +76,8 @@ public func >>> (left: T?, right: Map) { } -#if !swift(>=4.2) +// Code targeting the Swift 4.1 compiler and below. +#if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// Implicitly unwrapped optional object of basic type public func <- (left: inout T!, right: Map) { switch right.mappingType { @@ -126,7 +127,8 @@ public func >>> (left: T?, right: Map) { } -#if !swift(>=4.2) +// Code targeting the Swift 4.1 compiler and below. +#if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// Implicitly unwrapped optional Mappable objects public func <- (left: inout T!, right: Map) { switch right.mappingType { @@ -177,7 +179,8 @@ public func >>> (left: Dictionary?, right: Map) { } -#if !swift(>=4.2) +// Code targeting the Swift 4.1 compiler and below. +#if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// Implicitly unwrapped Optional Dictionary of Mappable object public func <- (left: inout Dictionary!, right: Map) { switch right.mappingType { @@ -225,7 +228,8 @@ public func >>> (left: Dictionary?, right: Map) { } -#if !swift(>=4.2) +// Code targeting the Swift 4.1 compiler and below. +#if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// Implicitly unwrapped Optional Dictionary of Mappable object public func <- (left: inout Dictionary!, right: Map) { switch right.mappingType { @@ -275,7 +279,8 @@ public func >>> (left: Array?, right: Map) { } -#if !swift(>=4.2) +// Code targeting the Swift 4.1 compiler and below. +#if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// Implicitly unwrapped Optional array of Mappable objects public func <- (left: inout Array!, right: Map) { switch right.mappingType { @@ -326,7 +331,8 @@ public func >>> (left: Array>?, right: Map) { } -#if !swift(>=4.2) +// Code targeting the Swift 4.1 compiler and below. +#if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// Implicitly unwrapped Optional array of Mappable objects public func <- (left: inout Array>!, right: Map) { switch right.mappingType { @@ -377,7 +383,8 @@ public func >>> (left: Set?, right: Map) { } -#if !swift(>=4.2) +// Code targeting the Swift 4.1 compiler and below. +#if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// Implicitly unwrapped Optional Set of Mappable objects public func <- (left: inout Set!, right: Map) { switch right.mappingType { diff --git a/Sources/TransformOperators.swift b/Sources/TransformOperators.swift index a2d60689..bd139518 100644 --- a/Sources/TransformOperators.swift +++ b/Sources/TransformOperators.swift @@ -54,7 +54,8 @@ public func >>> (left: Transform.Object?, right: (Map, } -#if !swift(>=4.2) +// Code targeting the Swift 4.1 compiler and below. +#if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// Implicitly unwrapped optional object of basic type with Transform public func <- (left: inout Transform.Object!, right: (Map, Transform)) { let (map, transform) = right @@ -113,7 +114,8 @@ public func >>> (left: [Transform.Object]?, right: (Ma } -#if !swift(>=4.2) +// Code targeting the Swift 4.1 compiler and below. +#if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// Implicitly unwrapped optional array of Basic type with Transform public func <- (left: inout [Transform.Object]!, right: (Map, Transform)) { let (map, transform) = right @@ -172,7 +174,8 @@ public func >>> (left: [String: Transform.Object]?, ri } -#if !swift(>=4.2) +// Code targeting the Swift 4.1 compiler and below. +#if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// Implicitly unwrapped optional dictionary of Basic type with Transform public func <- (left: inout [String: Transform.Object]!, right: (Map, Transform)) { let (map, transform) = right @@ -233,7 +236,8 @@ public func >>> (left: Transform.Object?, right: (Map, } -#if !swift(>=4.2) +// Code targeting the Swift 4.1 compiler and below. +#if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// Implicitly unwrapped optional Mappable objects that have transforms public func <- (left: inout Transform.Object!, right: (Map, Transform)) where Transform.Object: BaseMappable { let (map, transform) = right @@ -292,7 +296,8 @@ public func >>> (left: Dictionary=4.2) +// Code targeting the Swift 4.1 compiler and below. +#if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// Implicitly unwrapped Optional Dictionary of Mappable object with a transform public func <- (left: inout Dictionary!, right: (Map, Transform)) where Transform.Object: BaseMappable { let (map, transform) = right @@ -377,7 +382,8 @@ public func >>> (left: Dictionary=4.2) +// Code targeting the Swift 4.1 compiler and below. +#if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// Implicitly unwrapped Optional Dictionary of Mappable object with a transform public func <- (left: inout Dictionary!, right: (Map, Transform)) where Transform.Object: BaseMappable { let (map, transform) = right @@ -447,7 +453,8 @@ public func >>> (left: Array?, right } -#if !swift(>=4.2) +// Code targeting the Swift 4.1 compiler and below. +#if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// Implicitly unwrapped Optional array of Mappable objects public func <- (left: inout Array!, right: (Map, Transform)) where Transform.Object: BaseMappable { let (map, transform) = right @@ -543,7 +550,8 @@ public func >>> (left: [[Transform.Object]]?, right: ( } -#if !swift(>=4.2) +// Code targeting the Swift 4.1 compiler and below. +#if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// Implicitly unwrapped Optional array of array of objects with transform public func <- (left: inout [[Transform.Object]]!, right: (Map, Transform)) { let (map, transform) = right @@ -618,7 +626,8 @@ public func >>> (left: Set?, right: } -#if !swift(>=4.2) +// Code targeting the Swift 4.1 compiler and below. +#if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) /// Implicitly unwrapped Optional set of Mappable objects with transform public func <- (left: inout Set!, right: (Map, Transform)) where Transform.Object: BaseMappable { let (map, transform) = right