Skip to content

Commit

Permalink
Merge pull request #892 from Hearst-DD/swift-4
Browse files Browse the repository at this point in the history
Swift 4
  • Loading branch information
tristanhimmelman committed Sep 21, 2017
2 parents fb16bce + 1805155 commit c092a1d
Show file tree
Hide file tree
Showing 17 changed files with 203 additions and 174 deletions.
2 changes: 1 addition & 1 deletion .swift-version
@@ -1 +1 @@
3.2
4.0
24 changes: 11 additions & 13 deletions .travis.yml
@@ -1,5 +1,5 @@
language: objective-c
osx_image: xcode8.3
osx_image: xcode9

env:
global:
Expand All @@ -10,20 +10,18 @@ env:
- OSX_FRAMEWORK_SCHEME="ObjectMapper-Mac"
- TVOS_FRAMEWORK_SCHEME="ObjectMapper-tvOS"
- WATCHOS_FRAMEWORK_SCHEME="ObjectMapper-watchOS"
- IOS_SDK=iphonesimulator10.3
- OSX_SDK=macosx10.12
- TVOS_SDK=appletvsimulator10.2
- WATCHOS_SDK=watchsimulator3.2
- IOS_SDK=iphonesimulator11.0
- OSX_SDK=macosx10.13
- TVOS_SDK=appletvsimulator11.0
- WATCHOS_SDK=watchsimulator4.0
matrix:
- DESTINATION="OS=10.3.1,name=iPhone 5s" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES"
- DESTINATION="OS=10.3.1,name=iPhone 6" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES"
- DESTINATION="OS=10.3.1,name=iPhone 6 Plus" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES"
- DESTINATION="OS=10.3.1,name=iPhone 6s" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES"
- DESTINATION="OS=10.3.1,name=iPhone 6s Plus" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES"
- DESTINATION="OS=10.3.1,name=iPhone 7" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES"
- DESTINATION="OS=11.0,name=iPhone 5s" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES"
- DESTINATION="OS=11.0,name=iPhone 6" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES"
- DESTINATION="OS=11.0,name=iPhone 6s" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES"
- DESTINATION="OS=11.0,name=iPhone 7" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES"
- DESTINATION="arch=x86_64" SCHEME="$OSX_FRAMEWORK_SCHEME" SDK="$OSX_SDK" RUN_TESTS="YES"
- DESTINATION="OS=10.2,name=Apple TV 1080p" SCHEME="$TVOS_FRAMEWORK_SCHEME" SDK="$TVOS_SDK" RUN_TESTS="YES"
- DESTINATION="OS=3.2,name=Apple Watch - 38mm" SCHEME="$WATCHOS_FRAMEWORK_SCHEME" SDK="$WATCHOS_SDK" RUN_TESTS="NO"
- DESTINATION="OS=11.0,name=Apple TV 1080p" SCHEME="$TVOS_FRAMEWORK_SCHEME" SDK="$TVOS_SDK" RUN_TESTS="YES"
- DESTINATION="OS=4.0,name=Apple Watch - 38mm" SCHEME="$WATCHOS_FRAMEWORK_SCHEME" SDK="$WATCHOS_SDK" RUN_TESTS="NO"

before_install:
- gem install xcpretty --no-rdoc --no-ri --no-document --quiet
Expand Down
4 changes: 2 additions & 2 deletions ObjectMapper.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'ObjectMapper'
s.version = '2.2.9'
s.version = '3.0.0'
s.license = 'MIT'
s.summary = 'JSON Object mapping written in Swift'
s.homepage = 'https://github.com/Hearst-DD/ObjectMapper'
Expand All @@ -14,7 +14,7 @@ Pod::Spec.new do |s|


s.pod_target_xcconfig = {
'SWIFT_VERSION' => '3.2',
'SWIFT_VERSION' => '4.0',
}

s.requires_arc = true
Expand Down
38 changes: 27 additions & 11 deletions ObjectMapper.xcodeproj/project.pbxproj
Expand Up @@ -7,8 +7,6 @@
objects = {

/* Begin PBXBuildFile section */
030114A91D95187600FBFD4F /* ImmutableMappable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030114A81D95187600FBFD4F /* ImmutableMappable.swift */; };
030114AC1D951A4F00FBFD4F /* ImmutableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030114AA1D95197100FBFD4F /* ImmutableTests.swift */; };
030114AD1D951A5300FBFD4F /* ImmutableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030114AA1D95197100FBFD4F /* ImmutableTests.swift */; };
030114AE1D951A5600FBFD4F /* ImmutableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030114AA1D95197100FBFD4F /* ImmutableTests.swift */; };
030114AF1D951A6C00FBFD4F /* ImmutableMappable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030114A81D95187600FBFD4F /* ImmutableMappable.swift */; };
Expand Down Expand Up @@ -73,6 +71,8 @@
6AAC8FD319F048FE00E7A677 /* DateTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AAC8FCB19F048FE00E7A677 /* DateTransform.swift */; };
6AAE6A431ACED93500FBC899 /* ObjectMapper.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = CD1602FF1AC023D5000CD69A /* ObjectMapper.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
6AC458191BA350CF00054758 /* ObjectMapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 6AAC8F7B19F03C2900E7A677 /* ObjectMapper.h */; settings = {ATTRIBUTES = (Public, ); }; };
6AC53CAB1F031B85008BDDCD /* ImmutableMappable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030114A81D95187600FBFD4F /* ImmutableMappable.swift */; };
6AC53CAC1F03FA1B008BDDCD /* ImmutableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030114AA1D95197100FBFD4F /* ImmutableTests.swift */; };
6AC692341BE3FD3A004C119A /* Map.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6ACB15D11BC7F1D0006C029C /* Map.swift */; };
6AC692351BE3FD3A004C119A /* Mapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AAC8FC419F048FE00E7A677 /* Mapper.swift */; };
6AC692361BE3FD3A004C119A /* Operators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AAC8FC519F048FE00E7A677 /* Operators.swift */; };
Expand Down Expand Up @@ -643,7 +643,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0710;
LastUpgradeCheck = 0800;
LastUpgradeCheck = 0900;
ORGANIZATIONNAME = hearst;
TargetAttributes = {
6A05B7A51BE274BE00F19B53 = {
Expand All @@ -660,11 +660,11 @@
};
6AAC8F7519F03C2900E7A677 = {
CreatedOnToolsVersion = 6.0.1;
LastSwiftMigration = 0800;
LastSwiftMigration = 0900;
};
6AAC8F8019F03C2900E7A677 = {
CreatedOnToolsVersion = 6.0.1;
LastSwiftMigration = 0800;
LastSwiftMigration = 0900;
};
CD1602FE1AC023D5000CD69A = {
CreatedOnToolsVersion = 6.2;
Expand Down Expand Up @@ -841,6 +841,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
6AC53CAB1F031B85008BDDCD /* ImmutableMappable.swift in Sources */,
37AFD9B91AAD191C00AB59B5 /* CustomDateFormatTransform.swift in Sources */,
3BAD2C0C1BDDB10D00E6B203 /* Mappable.swift in Sources */,
6AF1488D1D99A7A6002BEA2C /* TransformOperators.swift in Sources */,
Expand All @@ -853,7 +854,6 @@
BC1E7F371ABC44C000F9B1CF /* EnumTransform.swift in Sources */,
D86BDEA41A51E5AD00120819 /* ISO8601DateTransform.swift in Sources */,
CD71C8C11A7218AD009D4161 /* TransformOf.swift in Sources */,
030114A91D95187600FBFD4F /* ImmutableMappable.swift in Sources */,
6A6C54D019FE8DB600239454 /* URLTransform.swift in Sources */,
038F0A031E55FE2400613148 /* IntegerOperators.swift in Sources */,
6A51372C1AADDE2700B82516 /* DateFormatterTransform.swift in Sources */,
Expand Down Expand Up @@ -891,7 +891,7 @@
6AAC8F8619F03C2900E7A677 /* ObjectMapperTests.swift in Sources */,
DC99C8CC1CA261A8005C788C /* NullableKeysFromJSONTests.swift in Sources */,
6100B1C01BD76A030011114A /* NestedArrayTests.swift in Sources */,
030114AC1D951A4F00FBFD4F /* ImmutableTests.swift in Sources */,
6AC53CAC1F03FA1B008BDDCD /* ImmutableTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1129,14 +1129,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -1180,14 +1186,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -1231,7 +1243,8 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.hearst.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(PROJECT_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.1;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
TVOS_DEPLOYMENT_TARGET = 9.0;
WATCHOS_DEPLOYMENT_TARGET = 2.0;
};
Expand All @@ -1252,7 +1265,8 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.hearst.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(PROJECT_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.1;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
TVOS_DEPLOYMENT_TARGET = 9.0;
WATCHOS_DEPLOYMENT_TARGET = 2.0;
};
Expand All @@ -1270,7 +1284,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.heart.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.1;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -1282,7 +1297,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.heart.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.1;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
16 changes: 9 additions & 7 deletions Sources/ImmutableMappable.swift
Expand Up @@ -108,7 +108,8 @@ public extension Map {
guard let jsonArray = currentValue as? [Any] else {
throw MapError(key: key, currentValue: currentValue, reason: "Cannot cast to '[Any]'", file: file, function: function, line: line)
}
return try jsonArray.enumerated().map { i, JSONObject -> T in

return try jsonArray.map { JSONObject -> T in
return try Mapper<T>(context: context).mapOrFail(JSONObject: JSONObject)
}
}
Expand All @@ -119,9 +120,10 @@ public extension Map {
guard let jsonArray = currentValue as? [Any] else {
throw MapError(key: key, currentValue: currentValue, reason: "Cannot cast to '[Any]'", file: file, function: function, line: line)
}
return try jsonArray.enumerated().map { i, json -> Transform.Object in

return try jsonArray.map { json -> Transform.Object in
guard let object = transform.transformFromJSON(json) else {
throw MapError(key: "\(key)[\(i)]", currentValue: json, reason: "Cannot transform to '\(Transform.Object.self)' using \(transform)", file: file, function: function, line: line)
throw MapError(key: "\(key)", currentValue: json, reason: "Cannot transform to '\(Transform.Object.self)' using \(transform)", file: file, function: function, line: line)
}
return object
}
Expand Down Expand Up @@ -183,16 +185,16 @@ public extension Map {
throw MapError(key: key, currentValue: currentValue, reason: "Cannot cast to '[[Any]]'",
file: file, function: function, line: line)
}
return try json2DArray.enumerated().map { i, jsonArray in
try jsonArray.enumerated().map { j, json -> Transform.Object in

return try json2DArray.map { jsonArray in
try jsonArray.map { 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)", currentValue: json, reason: "Cannot transform to '\(Transform.Object.self)' using \(transform)", file: file, function: function, line: line)
}
return object
}
}
}

}

public extension Mapper where N: ImmutableMappable {
Expand Down
20 changes: 10 additions & 10 deletions Sources/IntegerOperators.swift
Expand Up @@ -97,19 +97,19 @@ private func toSignedInteger<T: SignedInteger>(_ value: Any?) -> T? {
return nil
}

if T.self == Int.self, let x = Int(exactly: number.int64Value)?.toIntMax() {
if T.self == Int.self, let x = Int(exactly: number.int64Value) {
return T.init(x)
}
if T.self == Int8.self, let x = Int8(exactly: number.int64Value)?.toIntMax() {
if T.self == Int8.self, let x = Int8(exactly: number.int64Value) {
return T.init(x)
}
if T.self == Int16.self, let x = Int16(exactly: number.int64Value)?.toIntMax() {
if T.self == Int16.self, let x = Int16(exactly: number.int64Value) {
return T.init(x)
}
if T.self == Int32.self, let x = Int32(exactly: number.int64Value)?.toIntMax() {
if T.self == Int32.self, let x = Int32(exactly: number.int64Value) {
return T.init(x)
}
if T.self == Int64.self, let x = Int64(exactly: number.int64Value)?.toIntMax() {
if T.self == Int64.self, let x = Int64(exactly: number.int64Value) {
return T.init(x)
}

Expand All @@ -125,19 +125,19 @@ private func toUnsignedInteger<T: UnsignedInteger>(_ value: Any?) -> T? {
return nil
}

if T.self == UInt.self, let x = UInt(exactly: number.uint64Value)?.toUIntMax() {
if T.self == UInt.self, let x = UInt(exactly: number.uint64Value) {
return T.init(x)
}
if T.self == UInt8.self, let x = UInt8(exactly: number.uint64Value)?.toUIntMax() {
if T.self == UInt8.self, let x = UInt8(exactly: number.uint64Value) {
return T.init(x)
}
if T.self == UInt16.self, let x = UInt16(exactly: number.uint64Value)?.toUIntMax() {
if T.self == UInt16.self, let x = UInt16(exactly: number.uint64Value) {
return T.init(x)
}
if T.self == UInt32.self, let x = UInt32(exactly: number.uint64Value)?.toUIntMax() {
if T.self == UInt32.self, let x = UInt32(exactly: number.uint64Value) {
return T.init(x)
}
if T.self == UInt64.self, let x = UInt64(exactly: number.uint64Value)?.toUIntMax() {
if T.self == UInt64.self, let x = UInt64(exactly: number.uint64Value) {
return T.init(x)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/MapError.swift
Expand Up @@ -61,7 +61,7 @@ extension MapError: CustomStringConvertible {
("- key", key),
("- currentValue", currentValue),
]
let infoString = info.map { "\($0): \($1 ?? "nil")" }.joined(separator: "\n")
let infoString = info.map { "\($0.0): \($0.1 ?? "nil")" }.joined(separator: "\n")
return "Got an error while mapping.\n\(infoString)"
}

Expand Down
12 changes: 6 additions & 6 deletions Sources/Mapper.swift
Expand Up @@ -302,17 +302,17 @@ extension Mapper {

///Maps a dictionary of Objects that conform to Mappable to a JSON dictionary of dictionaries.
public func toJSONDictionary(_ dictionary: [String: N]) -> [String: [String: Any]] {
return dictionary.map { k, v in
return dictionary.map { (arg: (key: String, value: N)) in
// convert every value in dictionary to its JSON dictionary equivalent
return (k, self.toJSON(v))
return (arg.key, self.toJSON(arg.value))
}
}

///Maps a dictionary of Objects that conform to Mappable to a JSON dictionary of dictionaries.
public func toJSONDictionaryOfArrays(_ dictionary: [String: [N]]) -> [String: [[String: Any]]] {
return dictionary.map { k, v in
return dictionary.map { (arg: (key: String, value: [N])) in
// convert every value (array) in dictionary to its JSON dictionary equivalent
return (k, self.toJSONArray(v))
return (arg.key, self.toJSONArray(arg.value))
}
}

Expand Down Expand Up @@ -409,7 +409,7 @@ extension Mapper where N: Hashable {
}

extension Dictionary {
internal func map<K: Hashable, V>(_ f: (Element) throws -> (K, V)) rethrows -> [K: V] {
internal func map<K, V>(_ f: (Element) throws -> (K, V)) rethrows -> [K: V] {
var mapped = [K: V]()

for element in self {
Expand All @@ -420,7 +420,7 @@ extension Dictionary {
return mapped
}

internal func map<K: Hashable, V>(_ f: (Element) throws -> (K, [V])) rethrows -> [K: [V]] {
internal func map<K, V>(_ f: (Element) throws -> (K, [V])) rethrows -> [K: [V]] {
var mapped = [K: [V]]()

for element in self {
Expand Down

0 comments on commit c092a1d

Please sign in to comment.