diff --git a/APNSUtil.podspec b/APNSUtil.podspec index 7b9dfcd..2bc1b8b 100644 --- a/APNSUtil.podspec +++ b/APNSUtil.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'APNSUtil' - s.version = '1.0.0' + s.version = '1.1.0' s.summary = 'APNSUtil is makes code simple using apple push notification service.' s.description = 'APNSUtil is makes code simple using apple push notification service.' s.homepage = 'https://github.com/pisces/APNSUtil' @@ -17,5 +17,5 @@ Pod::Spec.new do |s| s.source = { :git => 'https://github.com/pisces/APNSUtil.git', :tag => s.version.to_s } s.ios.deployment_target = '9.0' s.source_files = 'APNSUtil/Classes/**/*' - s.dependency 'ObjectMapper', '~> 2.0' + s.dependency 'ObjectMapper', '~> 3.1' end diff --git a/APNSUtil.xcodeproj/project.pbxproj b/APNSUtil.xcodeproj/project.pbxproj index aed8b3e..d102c9d 100644 --- a/APNSUtil.xcodeproj/project.pbxproj +++ b/APNSUtil.xcodeproj/project.pbxproj @@ -284,7 +284,7 @@ PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -309,7 +309,7 @@ PRODUCT_BUNDLE_IDENTIFIER = pisces.lib.APNSUtil; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/Cartfile b/Cartfile index 5183114..fff49b9 100644 --- a/Cartfile +++ b/Cartfile @@ -1 +1 @@ -github "Hearst-DD/ObjectMapper" ~> 2.0 +github "Hearst-DD/ObjectMapper" ~> 3.1 diff --git a/Cartfile.resolved b/Cartfile.resolved index 7bfd90e..7b5372c 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1 +1 @@ -github "Hearst-DD/ObjectMapper" "2.2.9" +github "Hearst-DD/ObjectMapper" "3.1.0" diff --git a/Carthage/Checkouts/ObjectMapper/.swift-version b/Carthage/Checkouts/ObjectMapper/.swift-version index a3ec5a4..5186d07 100644 --- a/Carthage/Checkouts/ObjectMapper/.swift-version +++ b/Carthage/Checkouts/ObjectMapper/.swift-version @@ -1 +1 @@ -3.2 +4.0 diff --git a/Carthage/Checkouts/ObjectMapper/.travis.yml b/Carthage/Checkouts/ObjectMapper/.travis.yml index 012afe2..1987a9b 100644 --- a/Carthage/Checkouts/ObjectMapper/.travis.yml +++ b/Carthage/Checkouts/ObjectMapper/.travis.yml @@ -1,5 +1,5 @@ language: objective-c -osx_image: xcode8.3 +osx_image: xcode9 env: global: @@ -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 diff --git a/Carthage/Checkouts/ObjectMapper/ObjectMapper.podspec b/Carthage/Checkouts/ObjectMapper/ObjectMapper.podspec index c8c08d2..d741a41 100644 --- a/Carthage/Checkouts/ObjectMapper/ObjectMapper.podspec +++ b/Carthage/Checkouts/ObjectMapper/ObjectMapper.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'ObjectMapper' - s.version = '2.2.9' + s.version = '3.1.0' s.license = 'MIT' s.summary = 'JSON Object mapping written in Swift' s.homepage = 'https://github.com/Hearst-DD/ObjectMapper' @@ -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 diff --git a/Carthage/Checkouts/ObjectMapper/ObjectMapper.xcodeproj/project.pbxproj b/Carthage/Checkouts/ObjectMapper/ObjectMapper.xcodeproj/project.pbxproj index 77889d5..1394cc3 100644 --- a/Carthage/Checkouts/ObjectMapper/ObjectMapper.xcodeproj/project.pbxproj +++ b/Carthage/Checkouts/ObjectMapper/ObjectMapper.xcodeproj/project.pbxproj @@ -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 */; }; @@ -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 */; }; @@ -643,7 +643,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0710; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = hearst; TargetAttributes = { 6A05B7A51BE274BE00F19B53 = { @@ -660,14 +660,15 @@ }; 6AAC8F7519F03C2900E7A677 = { CreatedOnToolsVersion = 6.0.1; - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; }; 6AAC8F8019F03C2900E7A677 = { CreatedOnToolsVersion = 6.0.1; - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; }; CD1602FE1AC023D5000CD69A = { CreatedOnToolsVersion = 6.2; + LastSwiftMigration = 0900; }; CD1603081AC023D6000CD69A = { CreatedOnToolsVersion = 6.2; @@ -841,6 +842,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 */, @@ -853,7 +855,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 */, @@ -891,7 +892,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; }; @@ -994,7 +995,7 @@ PRODUCT_NAME = "$(PROJECT_NAME)"; SDKROOT = appletvos; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.1; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; WATCHOS_DEPLOYMENT_TARGET = 2.0; @@ -1023,7 +1024,7 @@ PRODUCT_NAME = "$(PROJECT_NAME)"; SDKROOT = appletvos; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.1; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; WATCHOS_DEPLOYMENT_TARGET = 2.0; @@ -1042,7 +1043,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.hearst.ObjectMapper-tvOSTests"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; - SWIFT_VERSION = 3.1; + SWIFT_VERSION = 4.0; TVOS_DEPLOYMENT_TARGET = 9.0; }; name = Debug; @@ -1060,7 +1061,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.hearst.ObjectMapper-tvOSTests"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; - SWIFT_VERSION = 3.1; + SWIFT_VERSION = 4.0; TVOS_DEPLOYMENT_TARGET = 9.0; }; name = Release; @@ -1086,7 +1087,7 @@ PRODUCT_NAME = "$(PROJECT_NAME)"; SDKROOT = watchos; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.1; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = 4; TVOS_DEPLOYMENT_TARGET = 9.0; WATCHOS_DEPLOYMENT_TARGET = 2.0; @@ -1114,7 +1115,7 @@ PRODUCT_NAME = "$(PROJECT_NAME)"; SDKROOT = watchos; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.1; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = 4; TVOS_DEPLOYMENT_TARGET = 9.0; WATCHOS_DEPLOYMENT_TARGET = 2.0; @@ -1129,14 +1130,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; @@ -1165,7 +1172,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.1; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -1180,14 +1187,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; @@ -1208,7 +1221,7 @@ MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.1; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -1231,7 +1244,8 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.hearst.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(PROJECT_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.1; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; TVOS_DEPLOYMENT_TARGET = 9.0; WATCHOS_DEPLOYMENT_TARGET = 2.0; }; @@ -1252,7 +1266,8 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.hearst.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(PROJECT_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.1; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; TVOS_DEPLOYMENT_TARGET = 9.0; WATCHOS_DEPLOYMENT_TARGET = 2.0; }; @@ -1270,7 +1285,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 = Default; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -1282,7 +1298,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 = Default; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -1309,7 +1326,7 @@ PRODUCT_NAME = "$(PROJECT_NAME)"; SDKROOT = macosx; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.1; + SWIFT_VERSION = 4.0; TVOS_DEPLOYMENT_TARGET = 9.0; WATCHOS_DEPLOYMENT_TARGET = 2.0; }; @@ -1336,7 +1353,7 @@ PRODUCT_NAME = "$(PROJECT_NAME)"; SDKROOT = macosx; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.1; + SWIFT_VERSION = 4.0; TVOS_DEPLOYMENT_TARGET = 9.0; WATCHOS_DEPLOYMENT_TARGET = 2.0; }; @@ -1357,7 +1374,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.heart.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; - SWIFT_VERSION = 3.1; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -1374,7 +1391,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.heart.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; - SWIFT_VERSION = 3.1; + SWIFT_VERSION = 4.0; }; name = Release; }; diff --git a/Carthage/Checkouts/ObjectMapper/ObjectMapper.xcodeproj/xcshareddata/xcschemes/ObjectMapper-Mac.xcscheme b/Carthage/Checkouts/ObjectMapper/ObjectMapper.xcodeproj/xcshareddata/xcschemes/ObjectMapper-Mac.xcscheme index c736780..1e2b3e5 100644 --- a/Carthage/Checkouts/ObjectMapper/ObjectMapper.xcodeproj/xcshareddata/xcschemes/ObjectMapper-Mac.xcscheme +++ b/Carthage/Checkouts/ObjectMapper/ObjectMapper.xcodeproj/xcshareddata/xcschemes/ObjectMapper-Mac.xcscheme @@ -1,6 +1,6 @@ @@ -36,6 +37,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/Carthage/Checkouts/ObjectMapper/Sources/HexColorTransform.swift b/Carthage/Checkouts/ObjectMapper/Sources/HexColorTransform.swift index dd9299f..ac045a3 100644 --- a/Carthage/Checkouts/ObjectMapper/Sources/HexColorTransform.swift +++ b/Carthage/Checkouts/ObjectMapper/Sources/HexColorTransform.swift @@ -35,8 +35,8 @@ open class HexColorTransform: TransformType { open func transformFromJSON(_ value: Any?) -> Object? { if let rgba = value as? String { if rgba.hasPrefix("#") { - let index = rgba.characters.index(rgba.startIndex, offsetBy: 1) - let hex = rgba.substring(from: index) + let index = rgba.index(rgba.startIndex, offsetBy: 1) + let hex = String(rgba[index...]) return getColor(hex: hex) } else { return getColor(hex: rgba) @@ -89,7 +89,7 @@ open class HexColorTransform: TransformType { let scanner = Scanner(string: hex) var hexValue: CUnsignedLongLong = 0 if scanner.scanHexInt64(&hexValue) { - switch (hex.characters.count) { + switch (hex.count) { case 3: red = CGFloat((hexValue & 0xF00) >> 8) / 15.0 green = CGFloat((hexValue & 0x0F0) >> 4) / 15.0 diff --git a/Carthage/Checkouts/ObjectMapper/Sources/ImmutableMappable.swift b/Carthage/Checkouts/ObjectMapper/Sources/ImmutableMappable.swift index 46ce555..d9d242a 100644 --- a/Carthage/Checkouts/ObjectMapper/Sources/ImmutableMappable.swift +++ b/Carthage/Checkouts/ObjectMapper/Sources/ImmutableMappable.swift @@ -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(context: context).mapOrFail(JSONObject: JSONObject) } } @@ -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 } @@ -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 { diff --git a/Carthage/Checkouts/ObjectMapper/Sources/IntegerOperators.swift b/Carthage/Checkouts/ObjectMapper/Sources/IntegerOperators.swift index 269c3bc..a4191e6 100644 --- a/Carthage/Checkouts/ObjectMapper/Sources/IntegerOperators.swift +++ b/Carthage/Checkouts/ObjectMapper/Sources/IntegerOperators.swift @@ -97,19 +97,19 @@ private func toSignedInteger(_ 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) } @@ -125,19 +125,19 @@ private func toUnsignedInteger(_ 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) } diff --git a/Carthage/Checkouts/ObjectMapper/Sources/MapError.swift b/Carthage/Checkouts/ObjectMapper/Sources/MapError.swift index 21e20cb..8e1c69a 100644 --- a/Carthage/Checkouts/ObjectMapper/Sources/MapError.swift +++ b/Carthage/Checkouts/ObjectMapper/Sources/MapError.swift @@ -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)" } diff --git a/Carthage/Checkouts/ObjectMapper/Sources/Mapper.swift b/Carthage/Checkouts/ObjectMapper/Sources/Mapper.swift index b3cd984..30e7b8b 100755 --- a/Carthage/Checkouts/ObjectMapper/Sources/Mapper.swift +++ b/Carthage/Checkouts/ObjectMapper/Sources/Mapper.swift @@ -280,6 +280,44 @@ public final class Mapper { } } +extension Mapper { + // MARK: Functions that create model from JSON file + + /// JSON file to Mappable object + /// - parameter JSONfile: Filename + /// - Returns: Mappable object + public func map(JSONfile: String) -> N? { + if let path = Bundle.main.path(forResource: JSONfile, ofType: nil) { + do { + let JSONString = try String(contentsOfFile: path) + do { + return self.map(JSONString: JSONString) + } + } catch { + return nil + } + } + return nil + } + + /// JSON file to Mappable object array + /// - parameter JSONfile: Filename + /// - Returns: Mappable object array + public func mapArray(JSONfile: String) -> [N]? { + if let path = Bundle.main.path(forResource: JSONfile, ofType: nil) { + do { + let JSONString = try String(contentsOfFile: path) + do { + return self.mapArray(JSONString: JSONString) + } + } catch { + return nil + } + } + return nil + } +} + extension Mapper { // MARK: Functions that create JSON from objects @@ -302,17 +340,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)) } } @@ -409,7 +447,7 @@ extension Mapper where N: Hashable { } extension Dictionary { - internal func map(_ f: (Element) throws -> (K, V)) rethrows -> [K: V] { + internal func map(_ f: (Element) throws -> (K, V)) rethrows -> [K: V] { var mapped = [K: V]() for element in self { @@ -420,7 +458,7 @@ extension Dictionary { return mapped } - internal func map(_ f: (Element) throws -> (K, [V])) rethrows -> [K: [V]] { + internal func map(_ f: (Element) throws -> (K, [V])) rethrows -> [K: [V]] { var mapped = [K: [V]]() for element in self { diff --git a/Carthage/Checkouts/ObjectMapper/Sources/ToJSON.swift b/Carthage/Checkouts/ObjectMapper/Sources/ToJSON.swift index 32c3432..bb53f61 100644 --- a/Carthage/Checkouts/ObjectMapper/Sources/ToJSON.swift +++ b/Carthage/Checkouts/ObjectMapper/Sources/ToJSON.swift @@ -34,14 +34,14 @@ private func setValue(_ value: Any, map: Map) { private func setValue(_ value: Any, key: String, checkForNestedKeys: Bool, delimiter: String, dictionary: inout [String : Any]) { if checkForNestedKeys { - let keyComponents = ArraySlice(key.components(separatedBy: delimiter).filter { !$0.isEmpty }.map { $0.characters }) + let keyComponents = ArraySlice(key.components(separatedBy: delimiter).filter { !$0.isEmpty }.map { $0 }) setValue(value, forKeyPathComponents: keyComponents, dictionary: &dictionary) } else { dictionary[key] = value } } -private func setValue(_ value: Any, forKeyPathComponents components: ArraySlice, dictionary: inout [String : Any]) { +private func setValue(_ value: Any, forKeyPathComponents components: ArraySlice, dictionary: inout [String : Any]) { if components.isEmpty { return } diff --git a/Carthage/Checkouts/ObjectMapper/Sources/TransformOperators.swift b/Carthage/Checkouts/ObjectMapper/Sources/TransformOperators.swift index a68f895..0a96e00 100644 --- a/Carthage/Checkouts/ObjectMapper/Sources/TransformOperators.swift +++ b/Carthage/Checkouts/ObjectMapper/Sources/TransformOperators.swift @@ -300,7 +300,8 @@ public func <- (left: inout Dictionary (String, [Transform.Object]) in + let transformedDictionary = dictionary.map { (arg: (key: String, values: [Any])) -> (String, [Transform.Object]) in + let (key, values) = arg if let jsonArray = fromJSONArrayWithTransform(values, transform: transform) { return (key, jsonArray) } @@ -320,8 +321,9 @@ public func >>> (left: Dictionary(left: inout Dictionary (String, [Transform.Object]) in + let transformedDictionary = dictionary.map { (arg: (key: String, values: [Any])) -> (String, [Transform.Object]) in + let (key, values) = arg if let jsonArray = fromJSONArrayWithTransform(values, transform: transform) { return (key, jsonArray) } @@ -343,7 +346,6 @@ public func <- (left: inout Dictionary>> (left: Dictionary(left: inout Dictionary (String, [Transform.Object]) in + let transformedDictionary = dictionary.map { (arg: (key: String, values: [Any])) -> (String, [Transform.Object]) in + let (key, values) = arg if let jsonArray = fromJSONArrayWithTransform(values, transform: transform) { return (key, jsonArray) } diff --git a/Carthage/Checkouts/ObjectMapper/Sources/URLTransform.swift b/Carthage/Checkouts/ObjectMapper/Sources/URLTransform.swift index 683a934..5624476 100644 --- a/Carthage/Checkouts/ObjectMapper/Sources/URLTransform.swift +++ b/Carthage/Checkouts/ObjectMapper/Sources/URLTransform.swift @@ -40,7 +40,7 @@ open class URLTransform: TransformType { to `NSURL(string:)` - returns: an initialized transformer */ - public init(shouldEncodeURLString: Bool = true, allowedCharacterSet: CharacterSet = .urlQueryAllowed) { + public init(shouldEncodeURLString: Bool = false, allowedCharacterSet: CharacterSet = .urlQueryAllowed) { self.shouldEncodeURLString = shouldEncodeURLString self.allowedCharacterSet = allowedCharacterSet } diff --git a/Carthage/Checkouts/ObjectMapper/Tests/ObjectMapperTests/BasicTypes.swift b/Carthage/Checkouts/ObjectMapper/Tests/ObjectMapperTests/BasicTypes.swift index 024d3a0..207c0f0 100644 --- a/Carthage/Checkouts/ObjectMapper/Tests/ObjectMapperTests/BasicTypes.swift +++ b/Carthage/Checkouts/ObjectMapper/Tests/ObjectMapperTests/BasicTypes.swift @@ -182,41 +182,41 @@ class BasicTypes: Mappable { intOptional <- map["intOpt"] intImplicityUnwrapped <- map["intImp"] - int8 <- map["int8"] - int8Optional <- map["int8Opt"] - int8ImplicityUnwrapped <- map["int8Imp"] + int8 <- map["int8"] + int8Optional <- map["int8Opt"] + int8ImplicityUnwrapped <- map["int8Imp"] - int16 <- map["int16"] - int16Optional <- map["int16Opt"] - int16ImplicityUnwrapped <- map["int16Imp"] + int16 <- map["int16"] + int16Optional <- map["int16Opt"] + int16ImplicityUnwrapped <- map["int16Imp"] - int32 <- map["int32"] - int32Optional <- map["int32Opt"] - int32ImplicityUnwrapped <- map["int32Imp"] + int32 <- map["int32"] + int32Optional <- map["int32Opt"] + int32ImplicityUnwrapped <- map["int32Imp"] - int64 <- map["int64"] - int64Optional <- map["int64Opt"] - int64ImplicityUnwrapped <- map["int64Imp"] + int64 <- map["int64"] + int64Optional <- map["int64Opt"] + int64ImplicityUnwrapped <- map["int64Imp"] - uint <- map["uint"] - uintOptional <- map["uintOpt"] - uintImplicityUnwrapped <- map["uintImp"] + uint <- map["uint"] + uintOptional <- map["uintOpt"] + uintImplicityUnwrapped <- map["uintImp"] - uint8 <- map["uint8"] - uint8Optional <- map["uint8Opt"] - uint8ImplicityUnwrapped <- map["uint8Imp"] + uint8 <- map["uint8"] + uint8Optional <- map["uint8Opt"] + uint8ImplicityUnwrapped <- map["uint8Imp"] - uint16 <- map["uint16"] - uint16Optional <- map["uint16Opt"] - uint16ImplicityUnwrapped <- map["uint16Imp"] + uint16 <- map["uint16"] + uint16Optional <- map["uint16Opt"] + uint16ImplicityUnwrapped <- map["uint16Imp"] - uint32 <- map["uint32"] - uint32Optional <- map["uint32Opt"] - uint32ImplicityUnwrapped <- map["uint32Imp"] + uint32 <- map["uint32"] + uint32Optional <- map["uint32Opt"] + uint32ImplicityUnwrapped <- map["uint32Imp"] - uint64 <- map["uint64"] - uint64Optional <- map["uint64Opt"] - uint64ImplicityUnwrapped <- map["uint64Imp"] + uint64 <- map["uint64"] + uint64Optional <- map["uint64Opt"] + uint64ImplicityUnwrapped <- map["uint64Imp"] double <- map["double"] doubleOptional <- map["doubleOpt"] diff --git a/Carthage/Checkouts/ObjectMapper/Tests/ObjectMapperTests/BasicTypesTestsFromJSON.swift b/Carthage/Checkouts/ObjectMapper/Tests/ObjectMapperTests/BasicTypesTestsFromJSON.swift index a3d9610..43b2ef6 100644 --- a/Carthage/Checkouts/ObjectMapper/Tests/ObjectMapperTests/BasicTypesTestsFromJSON.swift +++ b/Carthage/Checkouts/ObjectMapper/Tests/ObjectMapperTests/BasicTypesTestsFromJSON.swift @@ -58,101 +58,101 @@ class BasicTypesTestsFromJSON: XCTestCase { XCTAssertEqual(mappedObject?.boolImplicityUnwrapped, value) } - /// - warning: This test doens't consider about integer overflow/underflow. + /// - warning: This test doens't consider integer overflow/underflow. func testMappingIntegerFromJSON(){ - func parameterize(_ type: T.Type) { + func parameterize(_ type: T.Type) { let value: T = 123 let json: [String: Any] = [ "int": value, "intOpt": value, "intImp": value, - + "int8": value, "int8Opt": value, "int8Imp": value, - + "int16": value, "int16Opt": value, "int16Imp": value, - + "int32": value, "int32Opt": value, "int32Imp": value, - + "int64": value, "int64Opt": value, "int64Imp": value, - + "uint": value, "uintOpt": value, "uintImp": value, - + "uint8": value, "uint8Opt": value, "uint8Imp": value, - + "uint16": value, "uint16Opt": value, "uint16Imp": value, - + "uint32": value, "uint32Opt": value, "uint32Imp": value, - + "uint64": value, "uint64Opt": value, "uint64Imp": value, ] let mappedObject = mapper.map(JSON: json) XCTAssertNotNil(mappedObject) - + XCTAssertEqual(mappedObject?.int, 123) XCTAssertEqual(mappedObject?.intOptional, 123) XCTAssertEqual(mappedObject?.intImplicityUnwrapped, 123) - + XCTAssertEqual(mappedObject?.int8, 123) XCTAssertEqual(mappedObject?.int8Optional, 123) XCTAssertEqual(mappedObject?.int8ImplicityUnwrapped, 123) - + XCTAssertEqual(mappedObject?.int16, 123) XCTAssertEqual(mappedObject?.int16Optional, 123) XCTAssertEqual(mappedObject?.int16ImplicityUnwrapped, 123) - + XCTAssertEqual(mappedObject?.int32, 123) XCTAssertEqual(mappedObject?.int32Optional, 123) XCTAssertEqual(mappedObject?.int32ImplicityUnwrapped, 123) - + XCTAssertEqual(mappedObject?.int64, 123) XCTAssertEqual(mappedObject?.int64Optional, 123) XCTAssertEqual(mappedObject?.int64ImplicityUnwrapped, 123) - + XCTAssertEqual(mappedObject?.uint, 123) XCTAssertEqual(mappedObject?.uintOptional, 123) XCTAssertEqual(mappedObject?.uintImplicityUnwrapped, 123) - + XCTAssertEqual(mappedObject?.uint8, 123) XCTAssertEqual(mappedObject?.uint8Optional, 123) XCTAssertEqual(mappedObject?.uint8ImplicityUnwrapped, 123) - + XCTAssertEqual(mappedObject?.uint16, 123) XCTAssertEqual(mappedObject?.uint16Optional, 123) XCTAssertEqual(mappedObject?.uint16ImplicityUnwrapped, 123) - + XCTAssertEqual(mappedObject?.uint32, 123) XCTAssertEqual(mappedObject?.uint32Optional, 123) XCTAssertEqual(mappedObject?.uint32ImplicityUnwrapped, 123) - + XCTAssertEqual(mappedObject?.uint64, 123) XCTAssertEqual(mappedObject?.uint64Optional, 123) XCTAssertEqual(mappedObject?.uint64ImplicityUnwrapped, 123) } - + parameterize(Int.self) parameterize(Int8.self) parameterize(Int16.self) parameterize(Int32.self) parameterize(Int64.self) - + parameterize(UInt.self) parameterize(UInt8.self) parameterize(UInt16.self) @@ -378,7 +378,7 @@ class BasicTypesTestsFromJSON: XCTestCase { XCTAssertNotNil(mappedObject) XCTAssertEqual(mappedObject?.arrayFloat.first, value) XCTAssertEqual(mappedObject?.arrayFloatOptional?.first, value) - XCTAssertEqual(mappedObject?.arrayFloatImplicityUnwrapped.first, value) + XCTAssertEqual(mappedObject?.arrayFloatImplicityUnwrapped?.first, value) } func testMappingStringArrayFromJSON(){ @@ -458,7 +458,7 @@ class BasicTypesTestsFromJSON: XCTestCase { XCTAssertNotNil(mappedObject) XCTAssertEqual(mappedObject?.dictFloat[key], value) XCTAssertEqual(mappedObject?.dictFloatOptional?[key], value) - XCTAssertEqual(mappedObject?.dictFloatImplicityUnwrapped[key], value) + XCTAssertEqual(mappedObject?.dictFloatImplicityUnwrapped?[key], value) } func testMappingStringDictionaryFromJSON(){ @@ -471,7 +471,7 @@ class BasicTypesTestsFromJSON: XCTestCase { XCTAssertNotNil(mappedObject) XCTAssertEqual(mappedObject?.dictString[key], value) XCTAssertEqual(mappedObject?.dictStringOptional?[key], value) - XCTAssertEqual(mappedObject?.dictStringImplicityUnwrapped[key], value) + XCTAssertEqual(mappedObject?.dictStringImplicityUnwrapped?[key], value) } func testMappingAnyObjectDictionaryFromJSON(){ diff --git a/Carthage/Checkouts/ObjectMapper/Tests/ObjectMapperTests/ImmutableTests.swift b/Carthage/Checkouts/ObjectMapper/Tests/ObjectMapperTests/ImmutableTests.swift index 6d87935..80e71b3 100644 --- a/Carthage/Checkouts/ObjectMapper/Tests/ObjectMapperTests/ImmutableTests.swift +++ b/Carthage/Checkouts/ObjectMapper/Tests/ObjectMapperTests/ImmutableTests.swift @@ -32,43 +32,43 @@ import ObjectMapper class ImmutableObjectTests: XCTestCase { let JSON: [String: Any] = [ - + // Basic types "prop1": "Immutable!", "prop2": 255, "prop3": true, // prop4 has a default value - + // String "prop5": "prop5", "prop6": "prop6", "prop7": "prop7", - + // [String] "prop8": ["prop8"], "prop9": ["prop9"], "prop10": ["prop10"], - + // [String: String] "prop11": ["key": "prop11"], "prop12": ["key": "prop12"], "prop13": ["key": "prop13"], - + // Base "prop14": ["base": "prop14"], "prop15": ["base": "prop15"], "prop16": ["base": "prop16"], - + // [Base] "prop17": [["base": "prop17"]], "prop18": [["base": "prop18"]], "prop19": [["base": "prop19"]], - + // [String: Base] "prop20": ["key": ["base": "prop20"]], "prop21": ["key": ["base": "prop21"]], "prop22": ["key": ["base": "prop22"]], - + // Optional with immutables "prop23": "Optional", "prop24": 255, @@ -105,7 +105,7 @@ class ImmutableObjectTests: XCTestCase { "prop35": [[["base": "prop35"]]], "prop36": [[["base": "prop36"]]], "prop37": [[["base": "prop37"]]], - + "non.nested->key": "string", "nested": [ "int": 123, @@ -120,10 +120,9 @@ class ImmutableObjectTests: XCTestCase { "dictionary": ["a": 10, "b": 20, "c": 30], ] ] - + func testImmutableMappable() { let mapper = Mapper() - let immutable: Struct = try! mapper.map(JSON: JSON) XCTAssertNotNil(immutable) @@ -190,12 +189,12 @@ class ImmutableObjectTests: XCTestCase { XCTAssertEqual(immutable.prop37[0][0].base, "prop37") XCTAssertEqual(immutable.nonnestedString, "string") - + XCTAssertEqual(immutable.nestedInt, 123) XCTAssertEqual(immutable.nestedString, "hello") XCTAssertEqual(immutable.nestedArray, ["a", "b", "c"]) XCTAssertEqual(immutable.nestedDictionary, ["a": 10, "b": 20, "c": 30]) - + XCTAssertEqual(immutable.delimiterNestedInt, 123) XCTAssertEqual(immutable.delimiterNestedString, "hello") XCTAssertEqual(immutable.delimiterNestedArray, ["a", "b", "c"]) @@ -204,56 +203,56 @@ class ImmutableObjectTests: XCTestCase { let JSON2: [String: Any] = [ "prop1": "prop1", "prop2": NSNull() ] let immutable2 = try? mapper.map(JSON: JSON2) XCTAssertNil(immutable2) - + // TODO: ImmutableMappable to JSON let JSONFromObject = mapper.toJSON(immutable) let objectFromJSON = try? mapper.map(JSON: JSONFromObject) XCTAssertNotNil(objectFromJSON) assertImmutableObjectsEqual(objectFromJSON!, immutable) } - + func testMappingFromArray() { let JSONArray: [[String: Any]] = [JSON] - + let array: [Struct] = try! Mapper().mapArray(JSONArray: JSONArray) XCTAssertNotNil(array.first) } - + func testMappingFromDictionary() { let JSONDictionary: [String: [String: Any]] = [ "key1": JSON, "key2": JSON, ] - + let dictionary: [String: Struct] = try! Mapper().mapDictionary(JSON: JSONDictionary) XCTAssertNotNil(dictionary.first) XCTAssertEqual(dictionary.count, 2) XCTAssertEqual(Set(dictionary.keys), Set(["key1", "key2"])) } - + func testMappingFromDictionary_empty() { let JSONDictionary: [String: [String: Any]] = [:] - + let dictionary: [String: Struct] = try! Mapper().mapDictionary(JSON: JSONDictionary) XCTAssertTrue(dictionary.isEmpty) } - + func testMappingFromDictionary_throws() { let JSONDictionary: [String: [String: Any]] = [ "key1": JSON, "key2": ["invalid": "dictionary"], ] - + XCTAssertThrowsError(try Mapper().mapDictionary(JSON: JSONDictionary)) } - + func testMappingFromDictionaryOfArrays() { let JSONDictionary: [String: [[String: Any]]] = [ "key1": [JSON, JSON], "key2": [JSON], "key3": [], ] - + let dictionary: [String: [Struct]] = try! Mapper().mapDictionaryOfArrays(JSON: JSONDictionary) XCTAssertNotNil(dictionary.first) XCTAssertEqual(dictionary.count, 3) @@ -262,23 +261,23 @@ class ImmutableObjectTests: XCTestCase { XCTAssertEqual(dictionary["key2"]?.count, 1) XCTAssertEqual(dictionary["key3"]?.count, 0) } - + func testMappingFromDictionaryOfArrays_empty() { let JSONDictionary: [String: [[String: Any]]] = [:] - + let dictionary: [String: [Struct]] = try! Mapper().mapDictionaryOfArrays(JSON: JSONDictionary) XCTAssertTrue(dictionary.isEmpty) } - + func testMappingFromDictionaryOfArrays_throws() { let JSONDictionary: [String: [[String: Any]]] = [ "key1": [JSON], "key2": [["invalid": "dictionary"]], ] - + XCTAssertThrowsError(try Mapper().mapDictionaryOfArrays(JSON: JSONDictionary)) } - + func testMappingArrayOfArrays() { let JSONArray: [[[String: Any]]] = [ [JSON, JSON], @@ -292,13 +291,13 @@ class ImmutableObjectTests: XCTestCase { XCTAssertEqual(array[1].count, 1) XCTAssertEqual(array[2].count, 0) } - + func testMappingArrayOfArrays_empty() { let JSONArray: [[[String: Any]]] = [] let array: [[Struct]] = try! Mapper().mapArrayOfArrays(JSONObject: JSONArray) XCTAssertTrue(array.isEmpty) } - + func testMappingArrayOfArrays_throws() { let JSONArray: [[[String: Any]]] = [ [JSON], @@ -306,7 +305,7 @@ class ImmutableObjectTests: XCTestCase { ] XCTAssertThrowsError(try Mapper().mapArrayOfArrays(JSONObject: JSONArray)) } - + func testAsPropertyOfMappable() { struct ImmutableObject: ImmutableMappable { let value: String @@ -314,7 +313,7 @@ class ImmutableObjectTests: XCTestCase { self.value = try map.value("value") } } - + struct Object: Mappable { var immutable: ImmutableObject! init?(map: Map) {} @@ -322,7 +321,7 @@ class ImmutableObjectTests: XCTestCase { self.immutable <- map["immutable"] } } - + let json: [String: Any] = [ "immutable": [ "value": "Hello" @@ -331,7 +330,7 @@ class ImmutableObjectTests: XCTestCase { let object = Mapper().map(JSON: json) XCTAssertEqual(object?.immutable?.value, "Hello") } - + } struct Struct { @@ -369,7 +368,7 @@ struct Struct { var prop24: Int? var prop25: Bool? var prop26: Double? - + // RawRepresentable let prop27a: Int64Enum let prop27b: Int64Enum @@ -404,7 +403,7 @@ struct Struct { var nestedString: String var nestedArray: [String] var nestedDictionary: [String: Int] - + var delimiterNestedInt: Int var delimiterNestedString: String var delimiterNestedArray: [String] @@ -425,11 +424,11 @@ extension Struct: ImmutableMappable { prop8 = try map.value("prop8", using: stringTransform) prop9 = try? map.value("prop9", using: stringTransform) prop10 = try? map.value("prop10", using: stringTransform) - + prop11 = try map.value("prop11", using: stringTransform) prop12 = try? map.value("prop12", using: stringTransform) prop13 = try? map.value("prop13", using: stringTransform) - + prop14 = try map.value("prop14") prop15 = try? map.value("prop15") prop16 = try? map.value("prop16") @@ -469,14 +468,14 @@ extension Struct: ImmutableMappable { prop35 = try map.value("prop35") prop36 = try? map.value("prop36") prop37 = try? map.value("prop37") - + nonnestedString = try map.value("non.nested->key", nested: false) - + nestedInt = try map.value("nested.int") nestedString = try map.value("nested.string") nestedArray = try map.value("nested.array") nestedDictionary = try map.value("nested.dictionary") - + delimiterNestedInt = try map.value("com.hearst.ObjectMapper.nested->com.hearst.ObjectMapper.int", delimiter: "->") delimiterNestedString = try map.value("com.hearst.ObjectMapper.nested->com.hearst.ObjectMapper.string", delimiter: "->") delimiterNestedArray = try map.value("com.hearst.ObjectMapper.nested->array", delimiter: "->") @@ -484,11 +483,6 @@ extension Struct: ImmutableMappable { } mutating func mapping(map: Map) { - prop23 <- map["prop23"] - prop24 <- map["prop24"] - prop25 <- map["prop25"] - prop26 <- map["prop26"] - prop1 >>> map["prop1"] prop2 >>> map["prop2"] prop3 >>> map["prop3"] @@ -501,11 +495,11 @@ extension Struct: ImmutableMappable { prop8 >>> (map["prop8"], stringTransform) prop9 >>> (map["prop9"], stringTransform) prop10 >>> (map["prop10"], stringTransform) - + prop11 >>> (map["prop11"], stringTransform) prop12 >>> (map["prop12"], stringTransform) prop13 >>> (map["prop13"], stringTransform) - + prop14 >>> map["prop14"] prop15 >>> map["prop15"] prop16 >>> map["prop16"] @@ -518,6 +512,11 @@ extension Struct: ImmutableMappable { prop21 >>> map["prop21"] prop22 >>> map["prop22"] + prop23 <- map["prop23"] + prop24 <- map["prop24"] + prop25 <- map["prop25"] + prop26 <- map["prop26"] + prop27a >>> map["prop27a"] prop27b >>> map["prop27b"] prop27c >>> map["prop27c"] @@ -545,14 +544,14 @@ extension Struct: ImmutableMappable { prop35 >>> map["prop35"] prop36 >>> map["prop36"] prop37 >>> map["prop37"] - + nonnestedString >>> map["non.nested->key", nested: false] - + nestedInt >>> map["nested.int"] nestedString >>> map["nested.string"] nestedArray >>> map["nested.array"] nestedDictionary >>> map["nested.dictionary"] - + delimiterNestedInt >>> map["com.hearst.ObjectMapper.nested->com.hearst.ObjectMapper.int", delimiter: "->"] delimiterNestedString >>> map["com.hearst.ObjectMapper.nested->com.hearst.ObjectMapper.string", delimiter: "->"] delimiterNestedArray >>> map["com.hearst.ObjectMapper.nested->array", delimiter: "->"] @@ -605,3 +604,4 @@ private func assertImmutableObjectsEqual(_ lhs: Struct, _ rhs: Struct) { XCTAssertEqual("\(lhs.prop36 as Optional)", "\(rhs.prop36 as Optional)") XCTAssertEqual("\(lhs.prop37)", "\(rhs.prop37)") } + diff --git a/Carthage/Checkouts/ObjectMapper/Tests/ObjectMapperTests/MapContextTests.swift b/Carthage/Checkouts/ObjectMapper/Tests/ObjectMapperTests/MapContextTests.swift index 28eb14e..e419a1e 100644 --- a/Carthage/Checkouts/ObjectMapper/Tests/ObjectMapperTests/MapContextTests.swift +++ b/Carthage/Checkouts/ObjectMapper/Tests/ObjectMapperTests/MapContextTests.swift @@ -134,7 +134,7 @@ class MapContextTests: XCTestCase { // MARK: ImmutableMappable // MARK: Single - func testImmatableMappingWithContext() { + func testImmutableMappingWithContext() { let JSON = ["name": "Anton"] let context = ImmutableContext(isDeveloper: true) @@ -145,7 +145,7 @@ class MapContextTests: XCTestCase { XCTAssertEqual(person?.isDeveloper ?? !context.isDeveloper, context.isDeveloper) } - func testImmatableMappingWithContextViaMappableExtension() { + func testImmutableMappingWithContextViaMappableExtension() { let JSON = ["name": "Anton"] let context = ImmutableContext(isDeveloper: true) @@ -155,7 +155,7 @@ class MapContextTests: XCTestCase { XCTAssertEqual(person?.isDeveloper ?? !context.isDeveloper, context.isDeveloper) } - func testImmatableMappingWithoutContext() { + func testImmutableMappingWithoutContext() { let JSON = ["name": "Anton"] do { diff --git a/Carthage/Checkouts/ObjectMapper/Tests/ObjectMapperTests/ObjectMapperTests.swift b/Carthage/Checkouts/ObjectMapper/Tests/ObjectMapperTests/ObjectMapperTests.swift index 7a324ec..79341e6 100644 --- a/Carthage/Checkouts/ObjectMapper/Tests/ObjectMapperTests/ObjectMapperTests.swift +++ b/Carthage/Checkouts/ObjectMapper/Tests/ObjectMapperTests/ObjectMapperTests.swift @@ -54,11 +54,15 @@ class ObjectMapperTests: XCTestCase { let drinker = true let smoker = false let sex: Sex = .Female - let subUserJSON = "{\"identifier\" : \"user8723\", \"drinker\" : true, \"age\": 17, \"username\" : \"sub user\" }" + let canDrive = true + let subUserJSON = "{\"identifier\" : \"user8723\", \"drinker\" : true, \"age\": 17, \"username\" : \"sub user\", \"canDrive\": \(canDrive) }" - let userJSONString = "{\"username\":\"\(username)\",\"identifier\":\"\(identifier)\",\"photoCount\":\(photoCount),\"age\":\(age),\"drinker\":\(drinker),\"smoker\":\(smoker), \"sex\":\"\(sex.rawValue)\", \"arr\":[ \"bla\", true, 42 ], \"dict\":{ \"key1\" : \"value1\", \"key2\" : false, \"key3\" : 142 }, \"arrOpt\":[ \"bla\", true, 42 ], \"dictOpt\":{ \"key1\" : \"value1\", \"key2\" : false, \"key3\" : 142 }, \"weight\": \(weight), \"float\": \(float), \"friend\": \(subUserJSON), \"friendDictionary\":{ \"bestFriend\": \(subUserJSON)}}" + let userJSONString = "{\"username\":\"\(username)\",\"identifier\":\"\(identifier)\",\"photoCount\":\(photoCount),\"age\":\(age),\"drinker\":\(drinker),\"smoker\":\(smoker), \"sex\":\"\(sex.rawValue)\", \"canDrive\": \(canDrive), \"arr\":[ \"bla\", true, 42 ], \"dict\":{ \"key1\" : \"value1\", \"key2\" : false, \"key3\" : 142 }, \"arrOpt\":[ \"bla\", true, 42 ], \"dictOpt\":{ \"key1\" : \"value1\", \"key2\" : false, \"key3\" : 142 }, \"weight\": \(weight), \"float\": \(float), \"friend\": \(subUserJSON), \"friendDictionary\":{ \"bestFriend\": \(subUserJSON)}, \"friends\": [\(subUserJSON), \(subUserJSON)]}" - let user = userMapper.map(JSONString: userJSONString)! + guard let user = userMapper.map(JSONString: userJSONString) else { + XCTFail() + return + } XCTAssertNotNil(user) XCTAssertEqual(username, user.username) @@ -70,6 +74,10 @@ class ObjectMapperTests: XCTestCase { XCTAssertEqual(drinker, user.drinker) XCTAssertEqual(smoker, user.smoker) XCTAssertEqual(sex, user.sex) + XCTAssertEqual(canDrive, user.canDrive) + XCTAssertNotNil(user.friends) + XCTAssertEqual(user.friends?.count, 2) + XCTAssertEqual(user.friends?[1].canDrive, canDrive) //print(Mapper().toJSONString(user, prettyPrint: true)) } @@ -86,9 +94,9 @@ class ObjectMapperTests: XCTestCase { let sex: Sex = .Female let subUserJSON = "{\"identifier\" : \"user8723\", \"drinker\" : true, \"age\": 17, \"username\" : \"sub user\" }" - let userJSONString: String? = "{\"username\":\"\(username)\",\"identifier\":\"\(identifier)\",\"photoCount\":\(photoCount),\"age\":\(age),\"drinker\":\(drinker),\"smoker\":\(smoker), \"sex\":\"\(sex.rawValue)\", \"arr\":[ \"bla\", true, 42 ], \"dict\":{ \"key1\" : \"value1\", \"key2\" : false, \"key3\" : 142 }, \"arrOpt\":[ \"bla\", true, 42 ], \"dictOpt\":{ \"key1\" : \"value1\", \"key2\" : false, \"key3\" : 142 }, \"weight\": \(weight), \"float\": \(float), \"friend\": \(subUserJSON), \"friendDictionary\":{ \"bestFriend\": \(subUserJSON)}}" + let userJSONString = "{\"username\":\"\(username)\",\"identifier\":\"\(identifier)\",\"photoCount\":\(photoCount),\"age\":\(age),\"drinker\":\(drinker),\"smoker\":\(smoker), \"sex\":\"\(sex.rawValue)\", \"arr\":[ \"bla\", true, 42 ], \"dict\":{ \"key1\" : \"value1\", \"key2\" : false, \"key3\" : 142 }, \"arrOpt\":[ \"bla\", true, 42 ], \"dictOpt\":{ \"key1\" : \"value1\", \"key2\" : false, \"key3\" : 142 }, \"weight\": \(weight), \"float\": \(float), \"friend\": \(subUserJSON), \"friendDictionary\":{ \"bestFriend\": \(subUserJSON)}}" - let user = userMapper.map(JSONString: userJSONString!)! + let user = userMapper.map(JSONString: userJSONString)! XCTAssertNotNil(user) XCTAssertEqual(username, user.username) @@ -107,7 +115,7 @@ class ObjectMapperTests: XCTestCase { let identifier = "user8723" let photoCount = 13 let age = 1227 - let weight = 123.23 + let weight = 180.51 let float: Float = 123.231 let drinker = true let smoker = false @@ -553,6 +561,7 @@ class User: Mappable { var drinker: Bool = false var smoker: Bool? var sex: Sex? + var canDrive: Bool? var arr: [Any] = [] var arrOptional: [Any]? var dict: [String : Any] = [:] @@ -580,6 +589,7 @@ class User: Mappable { drinker <- map["drinker"] smoker <- map["smoker"] sex <- map["sex"] + canDrive <- map["canDrive"] arr <- map["arr"] arrOptional <- map["arrOpt"] dict <- map["dict"] diff --git a/Example/APNSUtil.xcodeproj/project.pbxproj b/Example/APNSUtil.xcodeproj/project.pbxproj index fa84969..2fec768 100644 --- a/Example/APNSUtil.xcodeproj/project.pbxproj +++ b/Example/APNSUtil.xcodeproj/project.pbxproj @@ -530,7 +530,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -546,7 +546,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Release; }; diff --git a/Example/Podfile.lock b/Example/Podfile.lock index a897b26..22bc20d 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -1,7 +1,7 @@ PODS: - - APNSUtil (1.0.0): - - ObjectMapper (~> 2.0) - - ObjectMapper (2.0.0) + - APNSUtil (1.1.0): + - ObjectMapper (~> 3.1) + - ObjectMapper (3.1.0) DEPENDENCIES: - APNSUtil (from `../`) @@ -11,8 +11,8 @@ EXTERNAL SOURCES: :path: ../ SPEC CHECKSUMS: - APNSUtil: c39a8a3327a2fc5df8a961cc0c766bd674073a35 - ObjectMapper: aed2570edabbd3c9b26c939e1cabdb6558f933e0 + APNSUtil: 773198a5bd978ac8417d947e408bfd0d3cb29047 + ObjectMapper: 20505058f54e5c3ca69e1d6de9897d152a5369a6 PODFILE CHECKSUM: 613e78454e33684404b49d733e0a3a475e0ef3f8 diff --git a/Example/Pods/Local Podspecs/APNSUtil.podspec.json b/Example/Pods/Local Podspecs/APNSUtil.podspec.json index 0912119..93ac766 100644 --- a/Example/Pods/Local Podspecs/APNSUtil.podspec.json +++ b/Example/Pods/Local Podspecs/APNSUtil.podspec.json @@ -1,6 +1,6 @@ { "name": "APNSUtil", - "version": "1.0.0", + "version": "1.1.0", "summary": "APNSUtil is makes code simple using apple push notification service.", "description": "APNSUtil is makes code simple using apple push notification service.", "homepage": "https://github.com/pisces/APNSUtil", @@ -13,7 +13,7 @@ }, "source": { "git": "https://github.com/pisces/APNSUtil.git", - "tag": "1.0.0" + "tag": "1.1.0" }, "platforms": { "ios": "9.0" @@ -21,7 +21,7 @@ "source_files": "APNSUtil/Classes/**/*", "dependencies": { "ObjectMapper": [ - "~> 2.0" + "~> 3.1" ] } } diff --git a/Example/Pods/Manifest.lock b/Example/Pods/Manifest.lock index a897b26..22bc20d 100644 --- a/Example/Pods/Manifest.lock +++ b/Example/Pods/Manifest.lock @@ -1,7 +1,7 @@ PODS: - - APNSUtil (1.0.0): - - ObjectMapper (~> 2.0) - - ObjectMapper (2.0.0) + - APNSUtil (1.1.0): + - ObjectMapper (~> 3.1) + - ObjectMapper (3.1.0) DEPENDENCIES: - APNSUtil (from `../`) @@ -11,8 +11,8 @@ EXTERNAL SOURCES: :path: ../ SPEC CHECKSUMS: - APNSUtil: c39a8a3327a2fc5df8a961cc0c766bd674073a35 - ObjectMapper: aed2570edabbd3c9b26c939e1cabdb6558f933e0 + APNSUtil: 773198a5bd978ac8417d947e408bfd0d3cb29047 + ObjectMapper: 20505058f54e5c3ca69e1d6de9897d152a5369a6 PODFILE CHECKSUM: 613e78454e33684404b49d733e0a3a475e0ef3f8 diff --git a/Example/Pods/ObjectMapper/ObjectMapper/Core/Operators.swift b/Example/Pods/ObjectMapper/ObjectMapper/Core/Operators.swift deleted file mode 100755 index 77617e3..0000000 --- a/Example/Pods/ObjectMapper/ObjectMapper/Core/Operators.swift +++ /dev/null @@ -1,795 +0,0 @@ -// -// Operators.swift -// ObjectMapper -// -// Created by Tristan Himmelman on 2014-10-09. -// -// The MIT License (MIT) -// -// Copyright (c) 2014-2015 Hearst -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -/** -* This file defines a new operator which is used to create a mapping between an object and a JSON key value. -* There is an overloaded operator definition for each type of object that is supported in ObjectMapper. -* This provides a way to add custom logic to handle specific types of objects -*/ - -infix operator <- - -// MARK:- Objects with Basic types - -/// Object of Basic type -public func <- (left: inout T, right: Map) { - switch right.mappingType { - case .fromJSON where right.isKeyPresent: - FromJSON.basicType(&left, object: right.value()) - case .toJSON: - ToJSON.basicType(left, map: right) - default: () - } -} - -/// Optional object of basic type -public func <- (left: inout T?, right: Map) { - switch right.mappingType { - case .fromJSON where right.isKeyPresent: - FromJSON.optionalBasicType(&left, object: right.value()) - case .toJSON: - ToJSON.optionalBasicType(left, map: right) - default: () - } -} - -/// Implicitly unwrapped optional object of basic type -public func <- (left: inout T!, right: Map) { - switch right.mappingType { - case .fromJSON where right.isKeyPresent: - FromJSON.optionalBasicType(&left, object: right.value()) - case .toJSON: - ToJSON.optionalBasicType(left, map: right) - default: () - } -} - -// MARK:- Raw Representable types - -/// Object of Raw Representable type -public func <- (left: inout T, right: Map) { - left <- (right, EnumTransform()) -} - -/// Optional Object of Raw Representable type -public func <- (left: inout T?, right: Map) { - left <- (right, EnumTransform()) -} - -/// Implicitly Unwrapped Optional Object of Raw Representable type -public func <- (left: inout T!, right: Map) { - left <- (right, EnumTransform()) -} - -// MARK:- Arrays of Raw Representable type - -/// Array of Raw Representable object -public func <- (left: inout [T], right: Map) { - left <- (right, EnumTransform()) -} - -/// Array of Raw Representable object -public func <- (left: inout [T]?, right: Map) { - left <- (right, EnumTransform()) -} - -/// Array of Raw Representable object -public func <- (left: inout [T]!, right: Map) { - left <- (right, EnumTransform()) -} - -// MARK:- Dictionaries of Raw Representable type - -/// Dictionary of Raw Representable object -public func <- (left: inout [String: T], right: Map) { - left <- (right, EnumTransform()) -} - -/// Dictionary of Raw Representable object -public func <- (left: inout [String: T]?, right: Map) { - left <- (right, EnumTransform()) -} - -/// Dictionary of Raw Representable object -public func <- (left: inout [String: T]!, right: Map) { - left <- (right, EnumTransform()) -} - -// MARK:- Transforms - -/// Object of Basic type with Transform -public func <- (left: inout Transform.Object, right: (Map, Transform)) { - let (map, transform) = right - switch map.mappingType { - case .fromJSON where map.isKeyPresent: - let value = transform.transformFromJSON(map.currentValue) - FromJSON.basicType(&left, object: value) - case .toJSON: - let value: Transform.JSON? = transform.transformToJSON(left) - ToJSON.optionalBasicType(value, map: map) - default: () - } -} - -/// Optional object of basic type with Transform -public func <- (left: inout Transform.Object?, right: (Map, Transform)) { - let (map, transform) = right - switch map.mappingType { - case .fromJSON where map.isKeyPresent: - let value = transform.transformFromJSON(map.currentValue) - FromJSON.optionalBasicType(&left, object: value) - case .toJSON: - let value: Transform.JSON? = transform.transformToJSON(left) - ToJSON.optionalBasicType(value, map: map) - default: () - } -} - -/// Implicitly unwrapped optional object of basic type with Transform -public func <- (left: inout Transform.Object!, right: (Map, Transform)) { - let (map, transform) = right - switch map.mappingType { - case .fromJSON where map.isKeyPresent: - let value = transform.transformFromJSON(map.currentValue) - FromJSON.optionalBasicType(&left, object: value) - case .toJSON: - let value: Transform.JSON? = transform.transformToJSON(left) - ToJSON.optionalBasicType(value, map: map) - default: () - } -} - -/// Array of Basic type with Transform -public func <- (left: inout [Transform.Object], right: (Map, Transform)) { - let (map, transform) = right - switch map.mappingType { - case .fromJSON where map.isKeyPresent: - let values = fromJSONArrayWithTransform(map.currentValue, transform: transform) - FromJSON.basicType(&left, object: values) - case .toJSON: - let values = toJSONArrayWithTransform(left, transform: transform) - ToJSON.optionalBasicType(values, map: map) - default: () - } -} - -/// Optional array of Basic type with Transform -public func <- (left: inout [Transform.Object]?, right: (Map, Transform)) { - let (map, transform) = right - switch map.mappingType { - case .fromJSON where map.isKeyPresent: - let values = fromJSONArrayWithTransform(map.currentValue, transform: transform) - FromJSON.optionalBasicType(&left, object: values) - case .toJSON: - let values = toJSONArrayWithTransform(left, transform: transform) - ToJSON.optionalBasicType(values, map: map) - default: () - } -} - -/// Implicitly unwrapped optional array of Basic type with Transform -public func <- (left: inout [Transform.Object]!, right: (Map, Transform)) { - let (map, transform) = right - switch map.mappingType { - case .fromJSON where map.isKeyPresent: - let values = fromJSONArrayWithTransform(map.currentValue, transform: transform) - FromJSON.optionalBasicType(&left, object: values) - case .toJSON: - let values = toJSONArrayWithTransform(left, transform: transform) - ToJSON.optionalBasicType(values, map: map) - default: () - } -} - -/// Dictionary of Basic type with Transform -public func <- (left: inout [String: Transform.Object], right: (Map, Transform)) { - let (map, transform) = right - switch map.mappingType { - case .fromJSON where map.isKeyPresent: - let values = fromJSONDictionaryWithTransform(map.currentValue, transform: transform) - FromJSON.basicType(&left, object: values) - case .toJSON: - let values = toJSONDictionaryWithTransform(left, transform: transform) - ToJSON.optionalBasicType(values, map: map) - default: () - } -} - -/// Optional dictionary of Basic type with Transform -public func <- (left: inout [String: Transform.Object]?, right: (Map, Transform)) { - let (map, transform) = right - switch map.mappingType { - case .fromJSON where map.isKeyPresent: - let values = fromJSONDictionaryWithTransform(map.currentValue, transform: transform) - FromJSON.optionalBasicType(&left, object: values) - case .toJSON: - let values = toJSONDictionaryWithTransform(left, transform: transform) - ToJSON.optionalBasicType(values, map: map) - default: () - } -} - -/// Implicitly unwrapped optional dictionary of Basic type with Transform -public func <- (left: inout [String: Transform.Object]!, right: (Map, Transform)) { - let (map, transform) = right - switch map.mappingType { - case .fromJSON where map.isKeyPresent: - let values = fromJSONDictionaryWithTransform(map.currentValue, transform: transform) - FromJSON.optionalBasicType(&left, object: values) - case .toJSON: - let values = toJSONDictionaryWithTransform(left, transform: transform) - ToJSON.optionalBasicType(values, map: map) - default: () - } -} - -private func fromJSONArrayWithTransform(_ input: Any?, transform: Transform) -> [Transform.Object]? { - if let values = input as? [AnyObject] { - return values.flatMap { value in - return transform.transformFromJSON(value) - } - } else { - return nil - } -} - -private func fromJSONDictionaryWithTransform(_ input: Any?, transform: Transform) -> [String: Transform.Object]? { - if let values = input as? [String: AnyObject] { - return values.filterMap { value in - return transform.transformFromJSON(value) - } - } else { - return nil - } -} - -private func toJSONArrayWithTransform(_ input: [Transform.Object]?, transform: Transform) -> [Transform.JSON]? { - return input?.flatMap { value in - return transform.transformToJSON(value) - } -} - -private func toJSONDictionaryWithTransform(_ input: [String: Transform.Object]?, transform: Transform) -> [String: Transform.JSON]? { - return input?.filterMap { value in - return transform.transformToJSON(value) - } -} - -// MARK:- Mappable Objects - - -/// Object conforming to Mappable -public func <- (left: inout T, right: Map) { - switch right.mappingType { - case .fromJSON: - FromJSON.object(&left, map: right) - case .toJSON: - ToJSON.object(left, map: right) - } -} - -/// Optional Mappable objects -public func <- (left: inout T?, right: Map) { - switch right.mappingType { - case .fromJSON where right.isKeyPresent: - FromJSON.optionalObject(&left, map: right) - case .toJSON: - ToJSON.optionalObject(left, map: right) - default: () - } -} - -/// Implicitly unwrapped optional Mappable objects -public func <- (left: inout T!, right: Map) { - switch right.mappingType { - case .fromJSON where right.isKeyPresent: - FromJSON.optionalObject(&left, map: right) - case .toJSON: - ToJSON.optionalObject(left, map: right) - default: () - } -} - -// MARK:- Transforms of Mappable Objects - - -/// Object conforming to Mappable that have transforms -public func <- (left: inout Transform.Object, right: (Map, Transform)) where Transform.Object: BaseMappable { - let (map, transform) = right - switch map.mappingType { - case .fromJSON where map.isKeyPresent: - let value: Transform.Object? = transform.transformFromJSON(map.currentValue) - FromJSON.basicType(&left, object: value) - case .toJSON: - let value: Transform.JSON? = transform.transformToJSON(left) - ToJSON.optionalBasicType(value, map: map) - default: () - } -} - -/// Optional Mappable objects that have transforms -public func <- (left: inout Transform.Object?, right: (Map, Transform)) where Transform.Object: BaseMappable { - let (map, transform) = right - switch map.mappingType { - case .fromJSON where map.isKeyPresent: - let value: Transform.Object? = transform.transformFromJSON(map.currentValue) - FromJSON.optionalBasicType(&left, object: value) - case .toJSON: - let value: Transform.JSON? = transform.transformToJSON(left) - ToJSON.optionalBasicType(value, map: map) - default: () - } -} - -/// 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 - switch map.mappingType { - case .fromJSON where map.isKeyPresent: - let value: Transform.Object? = transform.transformFromJSON(map.currentValue) - FromJSON.optionalBasicType(&left, object: value) - case .toJSON: - let value: Transform.JSON? = transform.transformToJSON(left) - ToJSON.optionalBasicType(value, map: map) - default: () - } -} - -// MARK:- Dictionary of Mappable objects - Dictionary - -/// Dictionary of Mappable objects -public func <- (left: inout Dictionary, right: Map) { switch right.mappingType { - case .fromJSON where right.isKeyPresent: - FromJSON.objectDictionary(&left, map: right) - case .toJSON: - ToJSON.objectDictionary(left, map: right) - default: () - } -} - -/// Optional Dictionary of Mappable object -public func <- (left: inout Dictionary?, right: Map) { - switch right.mappingType { - case .fromJSON where right.isKeyPresent: - FromJSON.optionalObjectDictionary(&left, map: right) - case .toJSON: - ToJSON.optionalObjectDictionary(left, map: right) - default: () - } -} - -/// Implicitly unwrapped Optional Dictionary of Mappable object -public func <- (left: inout Dictionary!, right: Map) { - switch right.mappingType { - case .fromJSON where right.isKeyPresent: - FromJSON.optionalObjectDictionary(&left, map: right) - case .toJSON: - ToJSON.optionalObjectDictionary(left, map: right) - default: () - } -} - -/// Dictionary of Mappable objects -public func <- (left: inout Dictionary, right: Map) { - switch right.mappingType { - case .fromJSON where right.isKeyPresent: - FromJSON.objectDictionaryOfArrays(&left, map: right) - case .toJSON: - ToJSON.objectDictionaryOfArrays(left, map: right) - default: () - } -} - -/// Optional Dictionary of Mappable object -public func <- (left: inout Dictionary?, right: Map) { - switch right.mappingType { - case .fromJSON where right.isKeyPresent: - FromJSON.optionalObjectDictionaryOfArrays(&left, map: right) - case .toJSON: - ToJSON.optionalObjectDictionaryOfArrays(left, map: right) - default: () - } -} - -/// Implicitly unwrapped Optional Dictionary of Mappable object -public func <- (left: inout Dictionary!, right: Map) { - switch right.mappingType { - case .fromJSON where right.isKeyPresent: - FromJSON.optionalObjectDictionaryOfArrays(&left, map: right) - case .toJSON: - ToJSON.optionalObjectDictionaryOfArrays(left, map: right) - default: () - } -} - -// MARK:- Dictionary of Mappable objects with a transform - Dictionary - -/// Dictionary of Mappable objects with a transform -public func <- (left: inout Dictionary, right: (Map, Transform)) where Transform.Object: BaseMappable { - let (map, transform) = right - if map.mappingType == .fromJSON && map.isKeyPresent, - let object = map.currentValue as? [String: AnyObject] { - let value = fromJSONDictionaryWithTransform(object as AnyObject?, transform: transform) ?? left - FromJSON.basicType(&left, object: value) - } else if map.mappingType == .toJSON { - let value = toJSONDictionaryWithTransform(left, transform: transform) - ToJSON.basicType(value, map: map) - } -} - -/// Optional Dictionary of Mappable object with a transform -public func <- (left: inout Dictionary?, right: (Map, Transform)) where Transform.Object: BaseMappable { - let (map, transform) = right - if map.mappingType == .fromJSON && map.isKeyPresent, let object = map.currentValue as? [String : AnyObject]{ - let value = fromJSONDictionaryWithTransform(object as AnyObject?, transform: transform) ?? left - FromJSON.optionalBasicType(&left, object: value) - } else if map.mappingType == .toJSON { - let value = toJSONDictionaryWithTransform(left, transform: transform) - ToJSON.optionalBasicType(value, map: map) - } -} - -/// 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 - if map.mappingType == .fromJSON && map.isKeyPresent, let dictionary = map.currentValue as? [String : AnyObject]{ - let transformedDictionary = fromJSONDictionaryWithTransform(dictionary as AnyObject?, transform: transform) ?? left - FromJSON.optionalBasicType(&left, object: transformedDictionary) - } else if map.mappingType == .toJSON { - let value = toJSONDictionaryWithTransform(left, transform: transform) - ToJSON.optionalBasicType(value, map: map) - } -} - -/// Dictionary of Mappable objects with a transform -public func <- (left: inout Dictionary, right: (Map, Transform)) where Transform.Object: BaseMappable { - let (map, transform) = right - - if let dictionary = map.currentValue as? [String : [AnyObject]], map.mappingType == .fromJSON && map.isKeyPresent { - let transformedDictionary = dictionary.map { (key: String, values: [AnyObject]) -> (String, [Transform.Object]) in - if let jsonArray = fromJSONArrayWithTransform(values, transform: transform) { - return (key, jsonArray) - } - if let leftValue = left[key] { - return (key, leftValue) - } - return (key, []) - } - - FromJSON.basicType(&left, object: transformedDictionary) - } else if map.mappingType == .toJSON { - let transformedDictionary = left.map { (key, values) in - return (key, toJSONArrayWithTransform(values, transform: transform) ?? []) - } - - ToJSON.basicType(transformedDictionary, map: map) - } -} - -/// Optional Dictionary of Mappable object with a transform -public func <- (left: inout Dictionary?, right: (Map, Transform)) where Transform.Object: BaseMappable { - let (map, transform) = right - - if let dictionary = map.currentValue as? [String : [AnyObject]], map.mappingType == .fromJSON && map.isKeyPresent { - - let transformedDictionary = dictionary.map { (key: String, values: [AnyObject]) -> (String, [Transform.Object]) in - if let jsonArray = fromJSONArrayWithTransform(values, transform: transform) { - return (key, jsonArray) - } - if let leftValue = left?[key] { - return (key, leftValue) - } - return (key, []) - - } - - FromJSON.optionalBasicType(&left, object: transformedDictionary) - } else if map.mappingType == .toJSON { - let transformedDictionary = left?.map { (key, values) in - return (key, toJSONArrayWithTransform(values, transform: transform) ?? []) - } - - ToJSON.optionalBasicType(transformedDictionary, map: map) - } -} - -/// 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 - - if let dictionary = map.currentValue as? [String : [AnyObject]], map.mappingType == .fromJSON && map.isKeyPresent { - let transformedDictionary = dictionary.map { (key: String, values: [AnyObject]) -> (String, [Transform.Object]) in - if let jsonArray = fromJSONArrayWithTransform(values, transform: transform) { - return (key, jsonArray) - } - if let leftValue = left?[key] { - return (key, leftValue) - } - return (key, []) - } - FromJSON.optionalBasicType(&left, object: transformedDictionary) - } else if map.mappingType == .toJSON { - let transformedDictionary = left?.map { (key, values) in - return (key, toJSONArrayWithTransform(values, transform: transform) ?? []) - } - - ToJSON.optionalBasicType(transformedDictionary, map: map) - } -} - -// MARK:- Array of Mappable objects - Array - -/// Array of Mappable objects -public func <- (left: inout Array, right: Map) { - switch right.mappingType { - case .fromJSON where right.isKeyPresent: - FromJSON.objectArray(&left, map: right) - case .toJSON: - ToJSON.objectArray(left, map: right) - default: () - } -} - -/// Optional array of Mappable objects -public func <- (left: inout Array?, right: Map) { - switch right.mappingType { - case .fromJSON where right.isKeyPresent: - FromJSON.optionalObjectArray(&left, map: right) - case .toJSON: - ToJSON.optionalObjectArray(left, map: right) - default: () - } -} - -/// Implicitly unwrapped Optional array of Mappable objects -public func <- (left: inout Array!, right: Map) { - switch right.mappingType { - case .fromJSON where right.isKeyPresent: - FromJSON.optionalObjectArray(&left, map: right) - case .toJSON: - ToJSON.optionalObjectArray(left, map: right) - default: () - } -} - -// MARK:- Array of Mappable objects with transforms - Array - -/// Array of Mappable objects -public func <- (left: inout Array, right: (Map, Transform)) where Transform.Object: BaseMappable { - let (map, transform) = right - switch map.mappingType { - case .fromJSON where map.isKeyPresent: - if let transformedValues = fromJSONArrayWithTransform(map.currentValue, transform: transform) { - FromJSON.basicType(&left, object: transformedValues) - } - case .toJSON: - let transformedValues = toJSONArrayWithTransform(left, transform: transform) - ToJSON.optionalBasicType(transformedValues, map: map) - default: () - } -} - -/// Optional array of Mappable objects -public func <- (left: inout Array?, right: (Map, Transform)) where Transform.Object: BaseMappable { - let (map, transform) = right - switch map.mappingType { - case .fromJSON where map.isKeyPresent: - let transformedValues = fromJSONArrayWithTransform(map.currentValue, transform: transform) - FromJSON.optionalBasicType(&left, object: transformedValues) - case .toJSON: - let transformedValues = toJSONArrayWithTransform(left, transform: transform) - ToJSON.optionalBasicType(transformedValues, map: map) - default: () - } -} - -/// Implicitly unwrapped Optional array of Mappable objects -public func <- (left: inout Array!, right: (Map, Transform)) where Transform.Object: BaseMappable { - let (map, transform) = right - switch map.mappingType { - case .fromJSON where map.isKeyPresent: - let transformedValues = fromJSONArrayWithTransform(map.currentValue, transform: transform) - FromJSON.optionalBasicType(&left, object: transformedValues) - case .toJSON: - let transformedValues = toJSONArrayWithTransform(left, transform: transform) - ToJSON.optionalBasicType(transformedValues, map: map) - default: () - } -} - -// MARK:- Array of Array of Mappable objects - Array> - -/// Array of Array Mappable objects -public func <- (left: inout Array>, right: Map) { - switch right.mappingType { - case .fromJSON where right.isKeyPresent: - FromJSON.twoDimensionalObjectArray(&left, map: right) - case .toJSON: - ToJSON.twoDimensionalObjectArray(left, map: right) - default: () - } -} - -/// Optional array of Mappable objects -public func <- (left:inout Array>?, right: Map) { - switch right.mappingType { - case .fromJSON where right.isKeyPresent: - FromJSON.optionalTwoDimensionalObjectArray(&left, map: right) - case .toJSON: - ToJSON.optionalTwoDimensionalObjectArray(left, map: right) - default: () - } -} - -/// Implicitly unwrapped Optional array of Mappable objects -public func <- (left: inout Array>!, right: Map) { - switch right.mappingType { - case .fromJSON where right.isKeyPresent: - FromJSON.optionalTwoDimensionalObjectArray(&left, map: right) - case .toJSON: - ToJSON.optionalTwoDimensionalObjectArray(left, map: right) - default: () - } -} - -// MARK:- Array of Array of Mappable objects - Array> with transforms - -/// Array of Array Mappable objects with transform -public func <- (left: inout Array>, right: (Map, Transform)) where Transform.Object: BaseMappable { - let (map, transform) = right - if map.mappingType == .fromJSON && map.isKeyPresent, let original2DArray = map.currentValue as? [[AnyObject]]{ - let transformed2DArray = original2DArray.flatMap { values in - fromJSONArrayWithTransform(values as AnyObject?, transform: transform) - } - FromJSON.basicType(&left, object: transformed2DArray) - } else if map.mappingType == .toJSON { - let transformed2DArray = left.flatMap { values in - toJSONArrayWithTransform(values, transform: transform) - } - ToJSON.basicType(transformed2DArray, map: map) - } -} - -/// Optional array of Mappable objects with transform -public func <- (left:inout Array>?, right: (Map, Transform)) where Transform.Object: BaseMappable { - let (map, transform) = right - if map.mappingType == .fromJSON && map.isKeyPresent, let original2DArray = map.currentValue as? [[AnyObject]]{ - let transformed2DArray = original2DArray.flatMap { values in - fromJSONArrayWithTransform(values as AnyObject?, transform: transform) - } - FromJSON.optionalBasicType(&left, object: transformed2DArray) - } else if map.mappingType == .toJSON { - let transformed2DArray = left?.flatMap { values in - toJSONArrayWithTransform(values, transform: transform) - } - ToJSON.optionalBasicType(transformed2DArray, map: map) - } -} - -/// Implicitly unwrapped Optional array of Mappable objects with transform -public func <- (left: inout Array>!, right: (Map, Transform)) where Transform.Object: BaseMappable { - let (map, transform) = right - if map.mappingType == .fromJSON && map.isKeyPresent, let original2DArray = map.currentValue as? [[AnyObject]] { - let transformed2DArray = original2DArray.flatMap { values in - fromJSONArrayWithTransform(values as AnyObject?, transform: transform) - } - FromJSON.optionalBasicType(&left, object: transformed2DArray) - } else if map.mappingType == .toJSON { - let transformed2DArray = left?.flatMap { values in - toJSONArrayWithTransform(values, transform: transform) - } - ToJSON.optionalBasicType(transformed2DArray, map: map) - } -} - -// MARK:- Set of Mappable objects - Set - -/// Set of Mappable objects -public func <- (left: inout Set, right: Map) where T: Hashable { - switch right.mappingType { - case .fromJSON where right.isKeyPresent: - FromJSON.objectSet(&left, map: right) - case .toJSON: - ToJSON.objectSet(left, map: right) - default: () - } -} - - -/// Optional Set of Mappable objects -public func <- (left: inout Set?, right: Map) where T: Hashable, T: Hashable { - switch right.mappingType { - case .fromJSON where right.isKeyPresent: - FromJSON.optionalObjectSet(&left, map: right) - case .toJSON: - ToJSON.optionalObjectSet(left, map: right) - default: () - } -} - -/// Implicitly unwrapped Optional Set of Mappable objects -public func <- (left: inout Set!, right: Map) where T: Hashable { - switch right.mappingType { - case .fromJSON where right.isKeyPresent: - FromJSON.optionalObjectSet(&left, map: right) - case .toJSON: - ToJSON.optionalObjectSet(left, map: right) - default: () - } -} - - -// MARK:- Set of Mappable objects with a transform - Set - -/// Set of Mappable objects with transform -public func <- (left: inout Set, right: (Map, Transform)) where Transform.Object: Hashable & Mappable { - let (map, transform) = right - switch map.mappingType { - case .fromJSON where map.isKeyPresent: - if let transformedValues = fromJSONArrayWithTransform(map.currentValue, transform: transform) { - FromJSON.basicType(&left, object: Set(transformedValues)) - } - case .toJSON: - let transformedValues = toJSONArrayWithTransform(Array(left), transform: transform) - ToJSON.optionalBasicType(transformedValues, map: map) - default: () - } -} - - -/// Optional Set of Mappable objects with transform -public func <- (left: inout Set?, right: (Map, Transform)) where Transform.Object: Hashable & Mappable { - let (map, transform) = right - switch map.mappingType { - case .fromJSON where map.isKeyPresent: - if let transformedValues = fromJSONArrayWithTransform(map.currentValue, transform: transform) { - FromJSON.basicType(&left, object: Set(transformedValues)) - } - case .toJSON: - if let values = left { - let transformedValues = toJSONArrayWithTransform(Array(values), transform: transform) - ToJSON.optionalBasicType(transformedValues, map: map) - } - default: () - } -} - -/// Implicitly unwrapped Optional set of Mappable objects with transform -public func <- (left: inout Set!, right: (Map, Transform)) where Transform.Object: Hashable & Mappable { - let (map, transform) = right - switch map.mappingType { - case .fromJSON where map.isKeyPresent: - if let transformedValues = fromJSONArrayWithTransform(map.currentValue, transform: transform) { - FromJSON.basicType(&left, object: Set(transformedValues)) - } - case .toJSON: - if let values = left { - let transformedValues = toJSONArrayWithTransform(Array(values), transform: transform) - ToJSON.optionalBasicType(transformedValues, map: map) - } - default: () - } -} diff --git a/Example/Pods/ObjectMapper/README-CN.md b/Example/Pods/ObjectMapper/README-CN.md new file mode 100644 index 0000000..b1a0209 --- /dev/null +++ b/Example/Pods/ObjectMapper/README-CN.md @@ -0,0 +1,502 @@ +# ObjectMapper-CN-Guide +> 文档由Swift老司机活动中心负责翻译,欢迎关注[@SwiftOldDriver](http://weibo.com/6062089411)。翻译有问题可以到 [ObjectMapper-CN-Guide](https://github.com/SwiftOldDriver/ObjectMapper-CN-Guide) 提 PR。 + +[ObjectMapper](https://github.com/Hearst-DD/ObjectMapper) 是一个使用 Swift 编写的用于 model 对象(类和结构体)和 JSON 之间转换的框架。 + +- [特性](#特性) +- [基础使用方法](#基础使用方法) +- [映射嵌套对象](#映射嵌套对象) +- [自定义转换规则](#自定义转换规则) +- [继承](#继承) +- [泛型对象](#泛型对象) +- [映射时的上下文对象](#映射时的上下文对象) +- [ObjectMapper + Alamofire](#objectmapper--alamofire) +- [ObjectMapper + Realm](#objectmapper--realm) +- [待完成](#待完成) +- [安装](#安装) + +# 特性: +- 把 JSON 映射成对象 +- 把对象映射 JSON +- 支持嵌套对象 (单独的成员变量、在数组或字典中都可以) +- 在转换过程支持自定义规则 +- 支持结构体( Struct ) +- [Immutable support](#immutablemappable-protocol-beta) (目前还在 beta ) + +# 基础使用方法 +为了支持映射,类或者结构体只需要实现```Mappable```协议。这个协议包含以下方法: +```swift +init?(map: Map) +mutating func mapping(map: Map) +``` +ObjectMapper使用自定义的```<-``` 运算符来声明成员变量和 JSON 的映射关系。 +```swift +class User: Mappable { + var username: String? + var age: Int? + var weight: Double! + var array: [AnyObject]? + var dictionary: [String : AnyObject] = [:] + var bestFriend: User? // 嵌套的 User 对象 + var friends: [User]? // Users 的数组 + var birthday: NSDate? + + required init?(map: Map) { + + } + + // Mappable + func mapping(map: Map) { + username <- map["username"] + age <- map["age"] + weight <- map["weight"] + array <- map["arr"] + dictionary <- map["dict"] + bestFriend <- map["best_friend"] + friends <- map["friends"] + birthday <- (map["birthday"], DateTransform()) + } +} + +struct Temperature: Mappable { + var celsius: Double? + var fahrenheit: Double? + + init?(map: Map) { + + } + + mutating func mapping(map: Map) { + celsius <- map["celsius"] + fahrenheit <- map["fahrenheit"] + } +} +``` + +一旦你的对象实现了 `Mappable`, ObjectMapper就可以让你轻松的实现和 JSON 之间的转换。 + +把 JSON 字符串转成 model 对象: + +```swift +let user = User(JSONString: JSONString) +``` + +把一个 model 转成 JSON 字符串: + +```swift +let JSONString = user.toJSONString(prettyPrint: true) +``` + +也可以使用`Mapper.swift`类来完成转换(这个类还额外提供了一些函数来处理一些特殊的情况: + +```swift +// 把 JSON 字符串转成 Model +let user = Mapper().map(JSONString: JSONString) +// 根据 Model 生成 JSON 字符串 +let JSONString = Mapper().toJSONString(user, prettyPrint: true) +``` + +ObjectMapper支持以下的类型映射到对象中: + +- `Int` +- `Bool` +- `Double` +- `Float` +- `String` +- `RawRepresentable` (枚举) +- `Array` +- `Dictionary` +- `Object` +- `Array` +- `Array>` +- `Set` +- `Dictionary` +- `Dictionary>` +- 以上所有的 Optional 类型 +- 以上所有的隐式强制解包类型(Implicitly Unwrapped Optional) + +## `Mappable` 协议 + +#### `mutating func mapping(map: Map)` +所有的映射最后都会调用到这个函数。当解析 JSON 时,这个函数会在对象创建成功后被执行。当生成 JSON 时就只有这个函数会被对象调用。 + +#### `init?(map: Map)` +这个可失败的初始化函数是 ObjectMapper 创建对象的时候使用的。开发者可以通过这个函数在映射前校验 JSON 。如果在这个方法里返回 nil 就不会执行 `mapping` 函数。可以通过传入的保存着 JSON 的 `Map` 对象进行校验: + +```swift +required init?(map: Map){ + // 检查 JSON 里是否有一定要有的 "name" 属性 + if map.JSONDictionary["name"] == nil { + return nil + } +} +``` + +## `StaticMappable` 协议 +`StaticMappable` 是 `Mappable` 之外的另一种选择。 这个协议可以让开发者通过一个静态函数初始化对象而不是通过 `init?(map: Map)`。 + +注意: `StaticMappable` 和 `Mappable` 都继承了 `BaseMappable` 协议。 `BaseMappable` 协议声明了 `mapping(map: Map)` 函数。 + +#### `static func objectForMapping(map: Map) -> BaseMappable?` +ObjectMapper 使用这个函数获取对象后进行映射。开发者需要在这个函数里返回一个实现 `BaseMappable` 对象的实例。这个函数也可以用于: + +- 在对象进行映射前校验 JSON +- 提供一个缓存过的对象用于映射 +- 返回另外一种类型的对象(当然是必须实现了 BaseMappable)用于映射。比如你可能通过检查 JSON 推断出用于映射的对象 ([看这个例子](https://github.com/Hearst-DD/ObjectMapper/blob/master/ObjectMapperTests/ClassClusterTests.swift#L62))。 + +如果你需要在 extension 里实现 ObjectMapper,你需要选择这个协议而不是 `Mappable` 。 + +## `ImmutableMappable` Protocol (Beta) + +> ⚠️ 这个特性还处于 Beta 阶段。正式发布时 API 可能会完全不同。 + +使用 `ImmutableMappable` 可以映射不可变的属性。下面的表格展示了 `ImmutableMappable` 和 `Mappable` 的不同: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ImmutableMappableMappable
Properties
+
+let id: Int
+let name: String?
+
+
+
+var id: Int!
+var name: String?
+
+
JSON -> Model
+
+init(map: Map) throws {
+  id   = try map.value("id")
+  name = try? map.value("name")
+}
+
+
+
+mutating func mapping(map: Map) {
+  id   <- map["id"]
+  name <- map["name"]
+}
+
+
Model -> JSON
+
+mutating func mapping(map: Map) {
+  id   >>> map["id"]
+  name >>> map["name"]
+}
+
+
+
+mutating func mapping(map: Map) {
+  id   <- map["id"]
+  name <- map["name"]
+}
+
+
Initializing
+
+try User(JSONString: JSONString)
+
+
+
+User(JSONString: JSONString)
+
+
+ +#### `init(map: Map) throws` + +这个可能抛出异常的初始化函数用于在提供的 `Map` 里映射不可变属性。每个不可变的初始化属性都要在这个初始化函数里初始化。 + +当发生下列情况时初始化函数会抛出一个错误: + +- `Map` 根据提供的键名获取不到对应值 +- `Map` 使用 `Transform` 后没有得到值 + +`ImmutableMappable` 使用 `Map.value(_:using:)` 方法从 `Map` 中获取值。因为可能抛出异常,这个方法在使用时需要使用 `try` 关键字。 `Optional` 的属性可以简单的用 `try?` 处理。 + +```swift +init(map: Map) throws { + name = try map.value("name") // throws an error when it fails + createdAt = try map.value("createdAt", using: DateTransform()) // throws an error when it fails + updatedAt = try? map.value("updatedAt", using: DateTransform()) // optional + posts = (try? map.value("posts")) ?? [] // optional + default value +} +``` + +#### `mutating func mapping(map: Map)` + +这个方法是在 Model 转回 JSON 时调用的。因为不可变的属性不能被 `<-` 映射,所以映射回来时需要使用 `>>>` 。 + +```swift +mutating func mapping(map: Map) { + name >>> map["name"] + createdAt >>> (map["createdAt"], DateTransform()) + updatedAt >>> (map["updatedAt"], DateTransform()) + posts >>> map["posts"] +} +``` +# 轻松映射嵌套对象 + +ObjectMapper 支持使用点语法来轻松实现嵌套对象的映射。比如有如下的 JSON 字符串: + +```json +"distance" : { + "text" : "102 ft", + "value" : 31 +} +``` +你可以通过这种写法直接访问到嵌套对象: + +```swift +func mapping(map: Map) { + distance <- map["distance.value"] +} +``` +嵌套的键名也支持访问数组中的值。如果有一个返回的 JSON 是一个包含 distance 的数组,可以通过这种写法访问: + +``` +distance <- map["distances.0.value"] +``` +如果你的键名刚好含有 `.` 符号,你需要特别声明关闭上面提到的获取嵌套对象功能: + +```swift +func mapping(map: Map) { + identifier <- map["app.identifier", nested: false] +} +``` +如果刚好有嵌套的对象的键名还有 `.` ,可以在中间加入一个自定义的分割符([#629](https://github.com/Hearst-DD/ObjectMapper/pull/629)): +```swift +func mapping(map: Map) { + appName <- map["com.myapp.info->com.myapp.name", delimiter: "->"] +} +``` +这种情况的 JSON 是这样的: + +```json +"com.myapp.info" : { + "com.myapp.name" : "SwiftOldDriver" +} +``` + +# 自定义转换规则 +ObjectMapper 也支持在映射时自定义转换规则。如果要使用自定义转换,创建一个 tuple(元祖)包含 ```map["field_name"]``` 和你要使用的变换放在 ```<-``` 的右边: + +```swift +birthday <- (map["birthday"], DateTransform()) +``` +当解析 JSON 时上面的转换会把 JSON 里面的 Int 值转成一个 NSDate ,如果是对象转为 JSON 时,则会把 NSDate 对象转成 Int 值。 + +只要实现```TransformType``` 协议就可以轻松的创建自定义的转换规则: + +```swift +public protocol TransformType { + associatedtype Object + associatedtype JSON + + func transformFromJSON(_ value: Any?) -> Object? + func transformToJSON(_ value: Object?) -> JSON? +} +``` + +### TransformOf +大多数情况下你都可以使用框架提供的转换类 ```TransformOf``` 来快速的实现一个期望的转换。 ```TransformOf``` 的初始化需要两个类型和两个闭包。两个类型声明了转换的目标类型和源类型,闭包则实现具体转换逻辑。 + +举个例子,如果你想要把一个 JSON 字符串转成 Int ,你可以像这样使用 ```TransformOf``` : + +```swift +let transform = TransformOf(fromJSON: { (value: String?) -> Int? in + // 把值从 String? 转成 Int? + return Int(value!) +}, toJSON: { (value: Int?) -> String? in + // 把值从 Int? 转成 String? + if let value = value { + return String(value) + } + return nil +}) + +id <- (map["id"], transform) +``` +这是一种更省略的写法: + +```swift +id <- (map["id"], TransformOf(fromJSON: { Int($0!) }, toJSON: { $0.map { String($0) } })) +``` +# 继承 + +实现了 ```Mappable``` 协议的类可以容易的被继承。当继承一个 mappable 的类时,使用这样的结构: + +```swift +class Base: Mappable { + var base: String? + + required init?(map: Map) { + + } + + func mapping(map: Map) { + base <- map["base"] + } +} + +class Subclass: Base { + var sub: String? + + required init?(map: Map) { + super.init(map) + } + + override func mapping(map: Map) { + super.mapping(map) + + sub <- map["sub"] + } +} +``` + +注意确认子类中的实现调用了父类中正确的初始化器和映射函数。 + +# 泛型对象 + +ObjectMapper 可以处理泛型只要这个泛型也实现了`Mappable`协议。看这个例子: + +```swift +class Result: Mappable { + var result: T? + + required init?(map: Map){ + + } + + func mapping(map: Map) { + result <- map["result"] + } +} + +let result = Mapper>().map(JSON) +``` +# 映射时的上下文对象 + +`Map` 是在映射时传入的对象,带有一个 optional `MapContext` 对象,开发者可以通过使用这个对象在映射时传入一些信息。 + +为了使用这个特性,需要先创建一个对象实现了 `MapContext` 协议(这个协议是空的),然后在初始化时传入 `Mapper` 中。 + +```swift +struct Context: MapContext { + var importantMappingInfo = "映射时需要知道的额外信息" +} + +class User: Mappable { + var name: String? + + required init?(map: Map){ + + } + + func mapping(map: Map){ + if let context = map.context as? Context { + // 获取到额外的信息 + } + } +} + +let context = Context() +let user = Mapper(context: context).map(JSONString) +``` + +# ObjectMapper + Alamofire + +如果网络层你使用的是 [Alamofire](https://github.com/Alamofire/Alamofire) ,并且你希望把返回的结果转换成 Swift 对象,你可以使用 [AlamofireObjectMapper](https://github.com/tristanhimmelman/AlamofireObjectMapper) 。这是一个使用 ObjectMapper 实现的把返回的 JSON 自动转成 Swift 对象的 Alamofire 的扩展。 + + +# ObjectMapper + Realm + +ObjectMapper 可以和 Realm 一起配合使用。使用下面的声明结构就可以使用 ObjectMapper 生成 Realm 对象: + +```swift +class Model: Object, Mappable { + dynamic var name = "" + + required convenience init?(map: Map) { + self.init() + } + + func mapping(map: Map) { + name <- map["name"] + } +} +``` + +如果你想要序列化相关联的 RealmObject,你可以使用 [ObjectMapper+Realm](https://github.com/jakenberg/ObjectMapper-Realm)。这是一个简单的 Realm 扩展,用于把任意的 JSON 序列化成 Realm 的类(ealm's List class。) + +注意:使用 ObjectMappers 的 `toJSON` 函数来生成 JSON 字符串只在 Realm 的写事务中有效(write transaction)。这是因为 ObjectMapper 在解析和生成时在映射函数( `<-` )中使用 `inout` 作为标记( flag )。Realm 会检测到标记并且强制要求 `toJSON` 函数只能在一个写的事务中调用,即使这个对象并没有被修改。 + +# 待完成 +- 改善错误的处理。可能使用 `throws` 来处理。 +- 相关类的文档完善 + +# 安装 +### Cocoapods +如果你的项目使用 [CocoaPods 0.36 及以上](http://blog.cocoapods.org/Pod-Authors-Guide-to-CocoaPods-Frameworks/) 的版本,你可以把下面内容添加到在 `Podfile` 中,将 ObjectMapper 添加到你的项目中: + +```ruby +pod 'ObjectMapper', '~> 2.2' +``` + +### Carthage +如果你的项目使用 [Carthage](https://github.com/Carthage/Carthage) ,你可以把下面的内容添加到 `Cartfile` 中,将 ObjectMapper 的依赖到你的项目中: + +``` +github "Hearst-DD/ObjectMapper" ~> 2.2 +``` + +### Swift Package Manager +如果你的项目使用 [Swift Package Manager](https://swift.org/package-manager/) ,那么你可以把下面内容添加到 `Package.swift` 中的 `dependencies` 数组中,将 ObjectMapper 的依赖到你的项目中: + +```swift +.Package(url: "https://github.com/Hearst-DD/ObjectMapper.git", majorVersion: 2, minor: 2), +``` + + +### Submodule +此外,ObjectMapper 也可以作为一个 submodule 添加到项目中: + +1. 打开终端,使用 `cd` 命令进入项目文件的根目录下,然后在终端中输入 `git submodule add https://github.com/Hearst-DD/ObjectMapper.git` ,把 ObjectMapper 作为项目的一个 [submodule](http://git-scm.com/docs/git-submodule) 添加进来。 +2. 打开 `ObjectMapper` 文件,并将 `ObjectMapper.xcodeproj` 拖进你 app 项目的文件导航中。 +3. 在 Xcode 中,文件导航中点击蓝色项目图标进入到 target 配置界面,在侧边栏的 "TARGETS" 下选择主工程对应的target。 +4. 确保 `ObjectMapper.framework` 的部署版本( deployment target )和主工程的部署版本保持一致。 +5. 在配置界面的顶部选项栏中,打开 "Build Phases" 面板。 +6. 展开 "Target Dependencies" 组,并添加 `ObjectMapper.framework` 。 +7. 点击面板左上角的 `+` 按钮,选择 "New Copy Files Phase"。将这个阶段重命名为 "Copy Frameworks",设置 "Destination" 为 "Frameworks",最后添加 `ObjectMapper.framework` 。 + + diff --git a/Example/Pods/ObjectMapper/README.md b/Example/Pods/ObjectMapper/README.md deleted file mode 100644 index e5f012e..0000000 --- a/Example/Pods/ObjectMapper/README.md +++ /dev/null @@ -1,351 +0,0 @@ -ObjectMapper -============ -[![CocoaPods](https://img.shields.io/cocoapods/v/ObjectMapper.svg)](https://github.com/Hearst-DD/ObjectMapper) -[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) -[![Build Status](https://travis-ci.org/Hearst-DD/ObjectMapper.svg?branch=master)](https://travis-ci.org/Hearst-DD/ObjectMapper) - -ObjectMapper is a framework written in Swift that makes it easy for you to convert your model objects (classes and structs) to and from JSON. - -- [Features](#features) -- [The Basics](#the-basics) -- [Mapping Nested Objects](#easy-mapping-of-nested-objects) -- [Custom Transformations](#custom-transforms) -- [Subclassing](#subclasses) -- [Generic Objects](#generic-objects) -- [Mapping Context](#mapping-context) -- [ObjectMapper + Alamofire](#objectmapper--alamofire) -- [ObjectMapper + Realm](#objectmapper--realm) -- [To Do](#to-do) -- [Contributing](#contributing) -- [Installation](#installation) - -# Features: -- Mapping JSON to objects -- Mapping objects to JSON -- Nested Objects (stand alone, in arrays or in dictionaries) -- Custom transformations during mapping -- Struct support - -# The Basics -To support mapping, a class or struct just needs to implement the ```Mappable``` protocol which includes the following functions: -```swift -init?(_ map: Map) -mutating func mapping(map: Map) -``` -ObjectMapper uses the ```<-``` operator to define how each member variable maps to and from JSON. - -```swift -class User: Mappable { - var username: String? - var age: Int? - var weight: Double! - var array: [AnyObject]? - var dictionary: [String : AnyObject] = [:] - var bestFriend: User? // Nested User object - var friends: [User]? // Array of Users - var birthday: NSDate? - - required init?(_ map: Map) { - - } - - // Mappable - func mapping(map: Map) { - username <- map["username"] - age <- map["age"] - weight <- map["weight"] - array <- map["arr"] - dictionary <- map["dict"] - bestFriend <- map["best_friend"] - friends <- map["friends"] - birthday <- (map["birthday"], DateTransform()) - } -} - -struct Temperature: Mappable { - var celsius: Double? - var fahrenheit: Double? - - init?(_ map: Map) { - - } - - mutating func mapping(map: Map) { - celsius <- map["celsius"] - fahrenheit <- map["fahrenheit"] - } -} -``` - -Once your class implements `Mappable`, ObjectMapper allows you to easily convert to and from JSON. - -Convert a JSON string to a model object: -```swift -let user = User(JSONString: JSONString) -``` - -Convert a model object to a JSON string: -```swift -let JSONString = user.toJSONString(prettyPrint: true) -``` - -Alternatively, the `Mapper.swift` class can also be used to accomplish the above (it also provides extra functionality for other situations): -``` -// Convert JSON String to Model -let user = Mapper().map(JSONString: JSONString) -// Create JSON String from Model -let JSONString = Mapper().toJSONString(user, prettyPrint: true) -``` - -ObjectMapper can map classes composed of the following types: -- `Int` -- `Bool` -- `Double` -- `Float` -- `String` -- `RawRepresentable` (Enums) -- `Array` -- `Dictionary` -- `Object` -- `Array` -- `Array>` -- `Set` -- `Dictionary` -- `Dictionary>` -- Optionals of all the above -- Implicitly Unwrapped Optionals of the above - -## `Mappable` Protocol - -#### `mutating func mapping(map: Map)` -This function is where all mapping definitions should go. When parsing JSON, this function is executed after successful object creation. When generating JSON, it is the only function that is called on the object. - -#### `init?(_ map: Map)` -This failable initializer is used by ObjectMapper for object creation. It can be used by developers to validate JSON prior to object serialization. Returning nil within the function will prevent the mapping from occuring. You can inspect the JSON stored within the `Map` object to do your validation: -```swift -required init?(_ map: Map){ - // check if a required "name" property exists within the JSON. - if map.JSONDictionary["name"] == nil { - return nil - } -} -``` - -## `StaticMappable` Protocol -`StaticMappable` is an alternative to `Mappable`. It provides developers with a static function that is used by ObjectMapper for object initialization instead of `init?(_ map: Map)`. - -Note: `StaticMappable`, like `Mappable`, is a sub protocol of `BaseMappable` which is where the `mapping(_ map: Map)` function is defined. - -#### `static func objectForMapping(map: Map) -> BaseMappable?` -ObjectMapper uses this function to get objects to use for mapping. Developers should return an instance of an object that conforms to `BaseMappable` in this function. This function can also be used to: -- validate JSON prior to object serialization -- provide an existing cached object to be used for mapping -- return an object of another type (which also conforms to BaseMappable) to be used for mapping. For instance, you may inspect the JSON to infer the type of object that should be used for mapping ([see example](https://github.com/Hearst-DD/ObjectMapper/blob/master/ObjectMapperTests/ClassClusterTests.swift#L62)) - -If you need to implemented ObjectMapper in an extension, you will need to select this protocol instead of `Mappable`. - -# Easy Mapping of Nested Objects -ObjectMapper supports dot notation within keys for easy mapping of nested objects. Given the following JSON String: -```json -"distance" : { - "text" : "102 ft", - "value" : 31 -} -``` -You can access the nested objects as follows: -```swift -func mapping(map: Map) { - distance <- map["distance.value"] -} -``` -Nested keys also support accessing values from an array. Given a JSON response with an array of distances, the value could be accessed as follows: -``` -distance <- map["distances.0.value"] -``` -If you have a key that contains `.`, you can individually disable the above feature as follows: -```swift -func mapping(map: Map) { - identifier <- map["app.identifier", nested: false] -} -``` - -# Custom Transforms -ObjectMapper also supports custom transforms that convert values during the mapping process. To use a transform, simply create a tuple with ```map["field_name"]``` and the transform of your choice on the right side of the ```<-``` operator: -```swift -birthday <- (map["birthday"], DateTransform()) -``` -The above transform will convert the JSON Int value to an NSDate when reading JSON and will convert the NSDate to an Int when converting objects to JSON. - -You can easily create your own custom transforms by adopting and implementing the methods in the ```TransformType``` protocol: -```swift -public protocol TransformType { - typealias Object - typealias JSON - - func transformFromJSON(value: AnyObject?) -> Object? - func transformToJSON(value: Object?) -> JSON? -} -``` - -### TransformOf -In a lot of situations you can use the built-in transform class ```TransformOf``` to quickly perform a desired transformation. ```TransformOf``` is initialized with two types and two closures. The types define what the transform is converting to and from and the closures perform the actual transformation. - -For example, if you want to transform a JSON String value to an Int you could use ```TransformOf``` as follows: -```swift -let transform = TransformOf(fromJSON: { (value: String?) -> Int? in - // transform value from String? to Int? - return Int(value!) -}, toJSON: { (value: Int?) -> String? in - // transform value from Int? to String? - if let value = value { - return String(value) - } - return nil -}) - -id <- (map["id"], transform) -``` -Here is a more condensed version of the above: -```swift -id <- (map["id"], TransformOf(fromJSON: { Int($0!) }, toJSON: { $0.map { String($0) } })) -``` - -# Subclasses - -Classes that implement the ```Mappable``` protocol can easily be subclassed. When subclassing mappable classes, follow the structure below: - -```swift -class Base: Mappable { - var base: String? - - required init?(_ map: Map) { - - } - - func mapping(map: Map) { - base <- map["base"] - } -} - -class Subclass: Base { - var sub: String? - - required init?(_ map: Map) { - super.init(map) - } - - override func mapping(map: Map) { - super.mapping(map) - - sub <- map["sub"] - } -} -``` - -Make sure your subclass implemenation calls the right initializers and mapping functions to also apply the mappings from your superclass. - -# Generic Objects - -ObjectMapper can handle classes with generic types as long as the generic type also conforms to `Mappable`. See the following example: -```swift -class Result: Mappable { - var result: T? - - required init?(_ map: Map){ - - } - - func mapping(map: Map) { - result <- map["result"] - } -} - -let result = Mapper>().map(JSON) -``` - -# Mapping Context - -The `Map` object which is passed around during mapping, has an optional `MapContext` object that is available for developers to use if they need to pass information around during mapping. - -To take advantage of this feature, simple create an object that implements `MapContext` (which is an empty protocol) and pass it into `Mapper` during initialization. -```swift -struct Context: MapContext { - var importantMappingInfo = "Info that I need during mapping" -} - -class User: Mappable { - var name: String? - - required init?(_ map: Map){ - - } - - func mapping(map: Map){ - if let context = map.context as? Context { - // use context to make decisions about mapping - } - } -} - -let context = Context() -let user = Mapper(context: context).map(JSONString) -``` - -#ObjectMapper + Alamofire - -If you are using [Alamofire](https://github.com/Alamofire/Alamofire) for networking and you want to convert your responses to Swift objects, you can use [AlamofireObjectMapper](https://github.com/tristanhimmelman/AlamofireObjectMapper). It is a simple Alamofire extension that uses ObjectMapper to automatically map JSON response data to Swift objects. - - -#ObjectMapper + Realm - -ObjectMapper and Realm can be used together. Simply follow the class structure below and you will be able to use ObjectMapper to generate your Realm models: - -```swift -class Model: Object, Mappable { - dynamic var name = "" - - required convenience init?(_ map: Map) { - self.init() - } - - func mapping(map: Map) { - name <- map["name"] - } -} -``` - -If you want to serialize associated RealmObjects, you can use [ObjectMapper+Realm](https://github.com/jakenberg/ObjectMapper-Realm). It is a simple Realm extension that serializes arbitrary JSON into Realm's List class. - -Note: Generating a JSON string of a Realm Object using ObjectMappers' `toJSON` function only works within a Realm write transaction. This is caused because ObjectMapper uses the `inout` flag in its mapping functions (`<-`) which are used both for serializing and deserializing. Realm detects the flag and forces the `toJSON` function to be called within a write block even though the objects are not being modified. - -# To Do -- Improve error handling. Perhaps using `throws` -- Class cluster documentation - -# Contributing - -Contributions are very welcome 👍😃. - -Before submitting any pull request, please ensure you have run the included tests and they have passed. If you are including new functionality, please write test cases for it as well. - -# Installation -ObjectMapper can be added to your project using [CocoaPods 0.36 or later](http://blog.cocoapods.org/Pod-Authors-Guide-to-CocoaPods-Frameworks/) by adding the following line to your `Podfile`: - -```ruby -pod 'ObjectMapper', '~> 1.3' -``` - -If you're using [Carthage](https://github.com/Carthage/Carthage) you can add a dependency on ObjectMapper by adding it to your `Cartfile`: -``` -github "Hearst-DD/ObjectMapper" ~> 1.3 -``` - -Otherwise, ObjectMapper can be added as a submodule: - -1. Add ObjectMapper as a [submodule](http://git-scm.com/docs/git-submodule) by opening the terminal, `cd`-ing into your top-level project directory, and entering the command `git submodule add https://github.com/Hearst-DD/ObjectMapper.git` -2. Open the `ObjectMapper` folder, and drag `ObjectMapper.xcodeproj` into the file navigator of your app project. -3. In Xcode, navigate to the target configuration window by clicking on the blue project icon, and selecting the application target under the "Targets" heading in the sidebar. -4. Ensure that the deployment target of `ObjectMapper.framework` matches that of the application target. -5. In the tab bar at the top of that window, open the "Build Phases" panel. -6. Expand the "Target Dependencies" group, and add `ObjectMapper.framework`. -7. Click on the `+` button at the top left of the panel and select "New Copy Files Phase". Rename this new phase to "Copy Frameworks", set the "Destination" to "Frameworks", and add `ObjectMapper.framework`. diff --git a/Example/Pods/ObjectMapper/ObjectMapper/Transforms/CustomDateFormatTransform.swift b/Example/Pods/ObjectMapper/Sources/CustomDateFormatTransform.swift similarity index 97% rename from Example/Pods/ObjectMapper/ObjectMapper/Transforms/CustomDateFormatTransform.swift rename to Example/Pods/ObjectMapper/Sources/CustomDateFormatTransform.swift index a4bf599..3cd5c59 100644 --- a/Example/Pods/ObjectMapper/ObjectMapper/Transforms/CustomDateFormatTransform.swift +++ b/Example/Pods/ObjectMapper/Sources/CustomDateFormatTransform.swift @@ -6,7 +6,7 @@ // // The MIT License (MIT) // -// Copyright (c) 2014-2015 Hearst +// Copyright (c) 2014-2016 Hearst // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Example/Pods/ObjectMapper/ObjectMapper/Transforms/DataTransform.swift b/Example/Pods/ObjectMapper/Sources/DataTransform.swift similarity index 91% rename from Example/Pods/ObjectMapper/ObjectMapper/Transforms/DataTransform.swift rename to Example/Pods/ObjectMapper/Sources/DataTransform.swift index c5285aa..d96f3d6 100644 --- a/Example/Pods/ObjectMapper/ObjectMapper/Transforms/DataTransform.swift +++ b/Example/Pods/ObjectMapper/Sources/DataTransform.swift @@ -6,7 +6,7 @@ // // The MIT License (MIT) // -// Copyright (c) 2014-2015 Hearst +// Copyright (c) 2014-2016 Hearst // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -34,14 +34,14 @@ open class DataTransform: TransformType { public init() {} - public func transformFromJSON(_ value: Any?) -> Data? { + open func transformFromJSON(_ value: Any?) -> Data? { guard let string = value as? String else{ return nil } return Data(base64Encoded: string) } - public func transformToJSON(_ value: Data?) -> String? { + open func transformToJSON(_ value: Data?) -> String? { guard let data = value else{ return nil } diff --git a/Example/Pods/ObjectMapper/ObjectMapper/Transforms/DateFormatterTransform.swift b/Example/Pods/ObjectMapper/Sources/DateFormatterTransform.swift similarity index 89% rename from Example/Pods/ObjectMapper/ObjectMapper/Transforms/DateFormatterTransform.swift rename to Example/Pods/ObjectMapper/Sources/DateFormatterTransform.swift index 5574c3f..fa75f3b 100644 --- a/Example/Pods/ObjectMapper/ObjectMapper/Transforms/DateFormatterTransform.swift +++ b/Example/Pods/ObjectMapper/Sources/DateFormatterTransform.swift @@ -6,7 +6,7 @@ // // The MIT License (MIT) // -// Copyright (c) 2014-2015 Hearst +// Copyright (c) 2014-2016 Hearst // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -32,20 +32,20 @@ open class DateFormatterTransform: TransformType { public typealias Object = Date public typealias JSON = String - let dateFormatter: DateFormatter + public let dateFormatter: DateFormatter public init(dateFormatter: DateFormatter) { self.dateFormatter = dateFormatter } - public func transformFromJSON(_ value: Any?) -> Date? { + open func transformFromJSON(_ value: Any?) -> Date? { if let dateString = value as? String { return dateFormatter.date(from: dateString) } return nil } - public func transformToJSON(_ value: Date?) -> String? { + open func transformToJSON(_ value: Date?) -> String? { if let date = value { return dateFormatter.string(from: date) } diff --git a/Example/Pods/ObjectMapper/ObjectMapper/Transforms/DateTransform.swift b/Example/Pods/ObjectMapper/Sources/DateTransform.swift similarity index 91% rename from Example/Pods/ObjectMapper/ObjectMapper/Transforms/DateTransform.swift rename to Example/Pods/ObjectMapper/Sources/DateTransform.swift index 989fa16..2c175cb 100644 --- a/Example/Pods/ObjectMapper/ObjectMapper/Transforms/DateTransform.swift +++ b/Example/Pods/ObjectMapper/Sources/DateTransform.swift @@ -6,7 +6,7 @@ // // The MIT License (MIT) // -// Copyright (c) 2014-2015 Hearst +// Copyright (c) 2014-2016 Hearst // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -34,7 +34,7 @@ open class DateTransform: TransformType { public init() {} - public func transformFromJSON(_ value: Any?) -> Date? { + open func transformFromJSON(_ value: Any?) -> Date? { if let timeInt = value as? Double { return Date(timeIntervalSince1970: TimeInterval(timeInt)) } @@ -46,7 +46,7 @@ open class DateTransform: TransformType { return nil } - public func transformToJSON(_ value: Date?) -> Double? { + open func transformToJSON(_ value: Date?) -> Double? { if let date = value { return Double(date.timeIntervalSince1970) } diff --git a/Example/Pods/ObjectMapper/ObjectMapper/Transforms/DictionaryTransform.swift b/Example/Pods/ObjectMapper/Sources/DictionaryTransform.swift similarity index 100% rename from Example/Pods/ObjectMapper/ObjectMapper/Transforms/DictionaryTransform.swift rename to Example/Pods/ObjectMapper/Sources/DictionaryTransform.swift diff --git a/Example/Pods/ObjectMapper/Sources/EnumOperators.swift b/Example/Pods/ObjectMapper/Sources/EnumOperators.swift new file mode 100644 index 0000000..5a1a667 --- /dev/null +++ b/Example/Pods/ObjectMapper/Sources/EnumOperators.swift @@ -0,0 +1,91 @@ +// +// EnumOperators.swift +// ObjectMapper +// +// Created by Tristan Himmelman on 2016-09-26. +// Copyright © 2016 hearst. All rights reserved. +// + +import Foundation + + +// MARK:- Raw Representable types + +/// Object of Raw Representable type +public func <- (left: inout T, right: Map) { + left <- (right, EnumTransform()) +} + +public func >>> (left: T, right: Map) { + left >>> (right, EnumTransform()) +} + + +/// Optional Object of Raw Representable type +public func <- (left: inout T?, right: Map) { + left <- (right, EnumTransform()) +} + +public func >>> (left: T?, right: Map) { + left >>> (right, EnumTransform()) +} + + +/// Implicitly Unwrapped Optional Object of Raw Representable type +public func <- (left: inout T!, right: Map) { + left <- (right, EnumTransform()) +} + +// MARK:- Arrays of Raw Representable type + +/// Array of Raw Representable object +public func <- (left: inout [T], right: Map) { + left <- (right, EnumTransform()) +} + +public func >>> (left: [T], right: Map) { + left >>> (right, EnumTransform()) +} + + +/// Array of Raw Representable object +public func <- (left: inout [T]?, right: Map) { + left <- (right, EnumTransform()) +} + +public func >>> (left: [T]?, right: Map) { + left >>> (right, EnumTransform()) +} + + +/// Array of Raw Representable object +public func <- (left: inout [T]!, right: Map) { + left <- (right, EnumTransform()) +} + +// MARK:- Dictionaries of Raw Representable type + +/// Dictionary of Raw Representable object +public func <- (left: inout [String: T], right: Map) { + left <- (right, EnumTransform()) +} + +public func >>> (left: [String: T], right: Map) { + left >>> (right, EnumTransform()) +} + + +/// Dictionary of Raw Representable object +public func <- (left: inout [String: T]?, right: Map) { + left <- (right, EnumTransform()) +} + +public func >>> (left: [String: T]?, right: Map) { + left >>> (right, EnumTransform()) +} + + +/// Dictionary of Raw Representable object +public func <- (left: inout [String: T]!, right: Map) { + left <- (right, EnumTransform()) +} diff --git a/Example/Pods/ObjectMapper/ObjectMapper/Transforms/EnumTransform.swift b/Example/Pods/ObjectMapper/Sources/EnumTransform.swift similarity index 91% rename from Example/Pods/ObjectMapper/ObjectMapper/Transforms/EnumTransform.swift rename to Example/Pods/ObjectMapper/Sources/EnumTransform.swift index b83d553..43e4ce7 100644 --- a/Example/Pods/ObjectMapper/ObjectMapper/Transforms/EnumTransform.swift +++ b/Example/Pods/ObjectMapper/Sources/EnumTransform.swift @@ -6,7 +6,7 @@ // // The MIT License (MIT) // -// Copyright (c) 2014-2015 Hearst +// Copyright (c) 2014-2016 Hearst // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -34,14 +34,14 @@ open class EnumTransform: TransformType { public init() {} - public func transformFromJSON(_ value: Any?) -> T? { + open func transformFromJSON(_ value: Any?) -> T? { if let raw = value as? T.RawValue { return T(rawValue: raw) } return nil } - public func transformToJSON(_ value: T?) -> T.RawValue? { + open func transformToJSON(_ value: T?) -> T.RawValue? { if let obj = value { return obj.rawValue } diff --git a/Example/Pods/ObjectMapper/ObjectMapper/Core/FromJSON.swift b/Example/Pods/ObjectMapper/Sources/FromJSON.swift similarity index 87% rename from Example/Pods/ObjectMapper/ObjectMapper/Core/FromJSON.swift rename to Example/Pods/ObjectMapper/Sources/FromJSON.swift index 336c8f1..952b42b 100755 --- a/Example/Pods/ObjectMapper/ObjectMapper/Core/FromJSON.swift +++ b/Example/Pods/ObjectMapper/Sources/FromJSON.swift @@ -6,7 +6,7 @@ // // The MIT License (MIT) // -// Copyright (c) 2014-2015 Hearst +// Copyright (c) 2014-2016 Hearst // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -48,7 +48,7 @@ internal final class FromJSON { /// Mappable object class func object(_ field: inout N, map: Map) { if map.toObject { - _ = Mapper(context: map.context).map(JSONObject: map.currentValue, toObject: field) + field = Mapper(context: map.context).map(JSONObject: map.currentValue, toObject: field) } else if let value: N = Mapper(context: map.context).map(JSONObject: map.currentValue) { field = value } @@ -57,8 +57,8 @@ internal final class FromJSON { /// Optional Mappable Object class func optionalObject(_ field: inout N?, map: Map) { - if let field = field , map.toObject && map.currentValue != nil { - _ = Mapper(context: map.context).map(JSONObject: map.currentValue, toObject: field) + if let f = field , map.toObject && map.currentValue != nil { + field = Mapper(context: map.context).map(JSONObject: map.currentValue, toObject: f) } else { field = Mapper(context: map.context).map(JSONObject: map.currentValue) } @@ -66,8 +66,8 @@ internal final class FromJSON { /// Implicitly unwrapped Optional Mappable Object class func optionalObject(_ field: inout N!, map: Map) { - if let field = field , map.toObject && map.currentValue != nil { - _ = Mapper(context: map.context).map(JSONObject: map.currentValue, toObject: field) + if let f = field , map.toObject && map.currentValue != nil { + field = Mapper(context: map.context).map(JSONObject: map.currentValue, toObject: f) } else { field = Mapper(context: map.context).map(JSONObject: map.currentValue) } @@ -119,7 +119,7 @@ internal final class FromJSON { /// Dctionary containing Mappable objects class func objectDictionary(_ field: inout Dictionary, map: Map) { if map.toObject { - _ = Mapper(context: map.context).mapDictionary(JSONObject: map.currentValue, toDictionary: field) + field = Mapper(context: map.context).mapDictionary(JSONObject: map.currentValue, toDictionary: field) } else { if let objects = Mapper(context: map.context).mapDictionary(JSONObject: map.currentValue) { field = objects @@ -129,8 +129,8 @@ internal final class FromJSON { /// Optional dictionary containing Mappable objects class func optionalObjectDictionary(_ field: inout Dictionary?, map: Map) { - if let field = field , map.toObject && map.currentValue != nil { - _ = Mapper(context: map.context).mapDictionary(JSONObject: map.currentValue, toDictionary: field) + if let f = field , map.toObject && map.currentValue != nil { + field = Mapper(context: map.context).mapDictionary(JSONObject: map.currentValue, toDictionary: f) } else { field = Mapper(context: map.context).mapDictionary(JSONObject: map.currentValue) } @@ -138,8 +138,8 @@ internal final class FromJSON { /// Implicitly unwrapped Dictionary containing Mappable objects class func optionalObjectDictionary(_ field: inout Dictionary!, map: Map) { - if let field = field , map.toObject && map.currentValue != nil { - _ = Mapper(context: map.context).mapDictionary(JSONObject: map.currentValue, toDictionary: field) + if let f = field , map.toObject && map.currentValue != nil { + field = Mapper(context: map.context).mapDictionary(JSONObject: map.currentValue, toDictionary: f) } else { field = Mapper(context: map.context).mapDictionary(JSONObject: map.currentValue) } diff --git a/Example/Pods/ObjectMapper/Sources/HexColorTransform.swift b/Example/Pods/ObjectMapper/Sources/HexColorTransform.swift new file mode 100644 index 0000000..ac045a3 --- /dev/null +++ b/Example/Pods/ObjectMapper/Sources/HexColorTransform.swift @@ -0,0 +1,126 @@ +// +// HexColorTransform.swift +// ObjectMapper +// +// Created by Vitaliy Kuzmenko on 10/10/16. +// Copyright © 2016 hearst. All rights reserved. +// + +#if os(iOS) || os(tvOS) || os(watchOS) +import UIKit +#elseif os(macOS) +import Cocoa +#endif + +#if os(iOS) || os(tvOS) || os(watchOS) || os(macOS) +open class HexColorTransform: TransformType { + + #if os(iOS) || os(tvOS) || os(watchOS) + public typealias Object = UIColor + #else + public typealias Object = NSColor + #endif + + public typealias JSON = String + + var prefix: Bool = false + + var alpha: Bool = false + + public init(prefixToJSON: Bool = false, alphaToJSON: Bool = false) { + alpha = alphaToJSON + prefix = prefixToJSON + } + + open func transformFromJSON(_ value: Any?) -> Object? { + if let rgba = value as? String { + if rgba.hasPrefix("#") { + let index = rgba.index(rgba.startIndex, offsetBy: 1) + let hex = String(rgba[index...]) + return getColor(hex: hex) + } else { + return getColor(hex: rgba) + } + } + return nil + } + + open func transformToJSON(_ value: Object?) -> JSON? { + if let value = value { + return hexString(color: value) + } + return nil + } + + fileprivate func hexString(color: Object) -> String { + let comps = color.cgColor.components! + let compsCount = color.cgColor.numberOfComponents + let r: Int + let g: Int + var b: Int + let a = Int(comps[compsCount - 1] * 255) + if compsCount == 4 { // RGBA + r = Int(comps[0] * 255) + g = Int(comps[1] * 255) + b = Int(comps[2] * 255) + } else { // Grayscale + r = Int(comps[0] * 255) + g = Int(comps[0] * 255) + b = Int(comps[0] * 255) + } + var hexString: String = "" + if prefix { + hexString = "#" + } + hexString += String(format: "%02X%02X%02X", r, g, b) + + if alpha { + hexString += String(format: "%02X", a) + } + return hexString + } + + fileprivate func getColor(hex: String) -> Object? { + var red: CGFloat = 0.0 + var green: CGFloat = 0.0 + var blue: CGFloat = 0.0 + var alpha: CGFloat = 1.0 + + let scanner = Scanner(string: hex) + var hexValue: CUnsignedLongLong = 0 + if scanner.scanHexInt64(&hexValue) { + switch (hex.count) { + case 3: + red = CGFloat((hexValue & 0xF00) >> 8) / 15.0 + green = CGFloat((hexValue & 0x0F0) >> 4) / 15.0 + blue = CGFloat(hexValue & 0x00F) / 15.0 + case 4: + red = CGFloat((hexValue & 0xF000) >> 12) / 15.0 + green = CGFloat((hexValue & 0x0F00) >> 8) / 15.0 + blue = CGFloat((hexValue & 0x00F0) >> 4) / 15.0 + alpha = CGFloat(hexValue & 0x000F) / 15.0 + case 6: + red = CGFloat((hexValue & 0xFF0000) >> 16) / 255.0 + green = CGFloat((hexValue & 0x00FF00) >> 8) / 255.0 + blue = CGFloat(hexValue & 0x0000FF) / 255.0 + case 8: + red = CGFloat((hexValue & 0xFF000000) >> 24) / 255.0 + green = CGFloat((hexValue & 0x00FF0000) >> 16) / 255.0 + blue = CGFloat((hexValue & 0x0000FF00) >> 8) / 255.0 + alpha = CGFloat(hexValue & 0x000000FF) / 255.0 + default: + // Invalid RGB string, number of characters after '#' should be either 3, 4, 6 or 8 + return nil + } + } else { + // "Scan hex error + return nil + } + #if os(iOS) || os(tvOS) || os(watchOS) + return UIColor(red: red, green: green, blue: blue, alpha: alpha) + #else + return NSColor(calibratedRed: red, green: green, blue: blue, alpha: alpha) + #endif + } +} +#endif diff --git a/Example/Pods/ObjectMapper/ObjectMapper/Transforms/ISO8601DateTransform.swift b/Example/Pods/ObjectMapper/Sources/ISO8601DateTransform.swift similarity index 76% rename from Example/Pods/ObjectMapper/ObjectMapper/Transforms/ISO8601DateTransform.swift rename to Example/Pods/ObjectMapper/Sources/ISO8601DateTransform.swift index b8898f7..2200423 100644 --- a/Example/Pods/ObjectMapper/ObjectMapper/Transforms/ISO8601DateTransform.swift +++ b/Example/Pods/ObjectMapper/Sources/ISO8601DateTransform.swift @@ -6,7 +6,7 @@ // // The MIT License (MIT) // -// Copyright (c) 2014-2015 Hearst +// Copyright (c) 2014-2016 Hearst // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -28,14 +28,20 @@ import Foundation +public extension DateFormatter { + public convenience init(withFormat format : String, locale : String) { + self.init() + self.locale = Locale(identifier: locale) + dateFormat = format + } +} + open class ISO8601DateTransform: DateFormatterTransform { + + static let reusableISODateFormatter = DateFormatter(withFormat: "yyyy-MM-dd'T'HH:mm:ssZZZZZ", locale: "en_US_POSIX") public init() { - let formatter = DateFormatter() - formatter.locale = Locale(identifier: "en_US_POSIX") - formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ" - - super.init(dateFormatter: formatter) + super.init(dateFormatter: ISO8601DateTransform.reusableISODateFormatter) } - } + diff --git a/Example/Pods/ObjectMapper/Sources/ImmutableMappable.swift b/Example/Pods/ObjectMapper/Sources/ImmutableMappable.swift new file mode 100644 index 0000000..d9d242a --- /dev/null +++ b/Example/Pods/ObjectMapper/Sources/ImmutableMappable.swift @@ -0,0 +1,317 @@ +// +// ImmutableMappble.swift +// ObjectMapper +// +// Created by Suyeol Jeon on 23/09/2016. +// +// The MIT License (MIT) +// +// Copyright (c) 2014-2016 Hearst +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +public protocol ImmutableMappable: BaseMappable { + init(map: Map) throws +} + +public extension ImmutableMappable { + + /// Implement this method to support object -> JSON transform. + public func mapping(map: Map) {} + + /// 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) + } + + /// Initializes object from a JSONObject + public init(JSONObject: Any, context: MapContext? = nil) throws { + self = try Mapper(context: context).map(JSONObject: JSONObject) + } + +} + +public extension Map { + + fileprivate func currentValue(for key: String, nested: Bool? = nil, delimiter: String = ".") -> Any? { + let isNested = nested ?? key.contains(delimiter) + return self[key, nested: isNested, delimiter: delimiter].currentValue + } + + // MARK: Basic + + /// Returns a value 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 { + let currentValue = self.currentValue(for: key, nested: nested, delimiter: delimiter) + guard let value = currentValue as? T else { + throw MapError(key: key, currentValue: currentValue, reason: "Cannot cast to '\(T.self)'", file: file, function: function, line: line) + } + return value + } + + /// Returns a transformed value 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 { + let currentValue = self.currentValue(for: key, nested: nested, delimiter: delimiter) + guard let value = transform.transformFromJSON(currentValue) else { + throw MapError(key: key, currentValue: currentValue, reason: "Cannot transform to '\(Transform.Object.self)' using \(transform)", file: file, function: function, line: line) + } + return value + } + + /// Returns a RawRepresentable type 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 { + return try self.value(key, nested: nested, delimiter: delimiter, using: EnumTransform(), file: file, function: function, line: line) + } + + /// Returns a `[RawRepresentable]` type 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] { + return try self.value(key, nested: nested, delimiter: delimiter, using: EnumTransform(), file: file, function: function, line: line) + } + + // MARK: BaseMappable + + /// Returns a `BaseMappable` object 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 { + let currentValue = self.currentValue(for: key, nested: nested, delimiter: delimiter) + guard let JSONObject = currentValue else { + throw MapError(key: key, currentValue: currentValue, reason: "Found unexpected nil value", file: file, function: function, line: line) + } + return try Mapper(context: context).mapOrFail(JSONObject: JSONObject) + } + + // 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] { + let currentValue = self.currentValue(for: key, nested: nested, delimiter: delimiter) + 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.map { JSONObject -> T in + return try Mapper(context: context).mapOrFail(JSONObject: JSONObject) + } + } + + /// 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] { + let currentValue = self.currentValue(for: key, nested: nested, delimiter: delimiter) + 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.map { json -> Transform.Object in + guard let object = transform.transformFromJSON(json) else { + throw MapError(key: "\(key)", currentValue: json, reason: "Cannot transform to '\(Transform.Object.self)' using \(transform)", file: file, function: function, line: line) + } + return object + } + } + + // MARK: [String: BaseMappable] + + /// 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) + } + var value: [String: T] = [:] + for (key, json) in jsonDictionary { + value[key] = try Mapper(context: context).mapOrFail(JSONObject: json) + } + return value + } + + /// 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) + } + var value: [String: Transform.Object] = [:] + for (key, json) in jsonDictionary { + guard let object = transform.transformFromJSON(json) else { + throw MapError(key: key, currentValue: json, reason: "Cannot transform to '\(Transform.Object.self)' using \(transform)", file: file, function: function, line: line) + } + value[key] = object + } + return value + } + + // 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]] { + + 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) + } + return try json2DArray.map { jsonArray in + try jsonArray.map { jsonObject -> T in + return try Mapper(context: context).mapOrFail(JSONObject: jsonObject) + } + } + } + + /// 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]] { + + 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) + } + + return try json2DArray.map { jsonArray in + try jsonArray.map { json -> Transform.Object in + guard let object = transform.transformFromJSON(json) else { + 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 { + + public func map(JSON: [String: Any]) throws -> N { + return try self.mapOrFail(JSON: JSON) + } + + public func map(JSONString: String) throws -> N { + return try mapOrFail(JSONString: JSONString) + } + + public func map(JSONObject: Any) throws -> N { + return try mapOrFail(JSONObject: JSONObject) + } + + // MARK: Array mapping functions + + public func mapArray(JSONArray: [[String: Any]]) throws -> [N] { + return try JSONArray.flatMap(mapOrFail) + } + + public func mapArray(JSONString: String) throws -> [N] { + guard let JSONObject = Mapper.parseJSONString(JSONString: JSONString) else { + throw MapError(key: nil, currentValue: JSONString, reason: "Cannot convert string into Any'") + } + + return try mapArray(JSONObject: JSONObject) + } + + public func mapArray(JSONObject: Any) throws -> [N] { + guard let JSONArray = JSONObject as? [[String: Any]] else { + throw MapError(key: nil, currentValue: JSONObject, reason: "Cannot cast to '[[String: Any]]'") + } + + return try mapArray(JSONArray: JSONArray) + } + + // MARK: Dictionary mapping functions + + public func mapDictionary(JSONString: String) throws -> [String: N] { + guard let JSONObject = Mapper.parseJSONString(JSONString: JSONString) else { + throw MapError(key: nil, currentValue: JSONString, reason: "Cannot convert string into Any'") + } + + return try mapDictionary(JSONObject: JSONObject) + } + + public func mapDictionary(JSONObject: Any?) throws -> [String: N] { + guard let JSON = JSONObject as? [String: [String: Any]] else { + throw MapError(key: nil, currentValue: JSONObject, reason: "Cannot cast to '[String: [String: Any]]''") + } + + return try mapDictionary(JSON: JSON) + } + + public func mapDictionary(JSON: [String: [String: Any]]) throws -> [String: N] { + return try JSON.filterMap(mapOrFail) + } + + // MARK: Dictinoary of arrays mapping functions + + public func mapDictionaryOfArrays(JSONObject: Any?) throws -> [String: [N]] { + guard let JSON = JSONObject as? [String: [[String: Any]]] else { + throw MapError(key: nil, currentValue: JSONObject, reason: "Cannot cast to '[String: [String: Any]]''") + } + return try mapDictionaryOfArrays(JSON: JSON) + } + + public func mapDictionaryOfArrays(JSON: [String: [[String: Any]]]) throws -> [String: [N]] { + return try JSON.filterMap { array -> [N] in + try mapArray(JSONArray: array) + } + } + + // MARK: 2 dimentional array mapping functions + + public func mapArrayOfArrays(JSONObject: Any?) throws -> [[N]] { + guard let JSONArray = JSONObject as? [[[String: Any]]] else { + throw MapError(key: nil, currentValue: JSONObject, reason: "Cannot cast to '[[[String: Any]]]''") + } + return try JSONArray.map(mapArray) + } + +} + +internal extension Mapper { + + internal func mapOrFail(JSON: [String: Any]) throws -> N { + let map = Map(mappingType: .fromJSON, JSON: JSON, context: context, shouldIncludeNilValues: shouldIncludeNilValues) + + // Check if object is ImmutableMappable, if so use ImmutableMappable protocol for mapping + if let klass = N.self as? ImmutableMappable.Type, + var object = try klass.init(map: map) as? N { + object.mapping(map: map) + return object + } + + // If not, map the object the standard way + guard let value = self.map(JSON: JSON) else { + throw MapError(key: nil, currentValue: JSON, reason: "Cannot map to '\(N.self)'") + } + return value + } + + internal func mapOrFail(JSONString: String) throws -> N { + guard let JSON = Mapper.parseJSONStringIntoDictionary(JSONString: JSONString) else { + throw MapError(key: nil, currentValue: JSONString, reason: "Cannot parse into '[String: Any]'") + } + return try mapOrFail(JSON: JSON) + } + + internal func mapOrFail(JSONObject: Any) throws -> N { + guard let JSON = JSONObject as? [String: Any] else { + throw MapError(key: nil, currentValue: JSONObject, reason: "Cannot cast to '[String: Any]'") + } + return try mapOrFail(JSON: JSON) + } + +} diff --git a/Example/Pods/ObjectMapper/Sources/IntegerOperators.swift b/Example/Pods/ObjectMapper/Sources/IntegerOperators.swift new file mode 100644 index 0000000..a4191e6 --- /dev/null +++ b/Example/Pods/ObjectMapper/Sources/IntegerOperators.swift @@ -0,0 +1,145 @@ +// +// IntegerOperators.swift +// ObjectMapper +// +// Created by Suyeol Jeon on 17/02/2017. +// Copyright © 2017 hearst. All rights reserved. +// + +import Foundation + +// MARK: - Signed Integer + +/// SignedInteger mapping +public func <- (left: inout T, right: Map) { + switch right.mappingType { + case .fromJSON where right.isKeyPresent: + let value: T = toSignedInteger(right.currentValue) ?? 0 + FromJSON.basicType(&left, object: value) + case .toJSON: + left >>> right + default: () + } +} + +/// Optional SignedInteger mapping +public func <- (left: inout T?, right: Map) { + switch right.mappingType { + case .fromJSON where right.isKeyPresent: + let value: T? = toSignedInteger(right.currentValue) + FromJSON.basicType(&left, object: value) + case .toJSON: + left >>> right + default: () + } +} + +/// ImplicitlyUnwrappedOptional SignedInteger mapping +public func <- (left: inout T!, right: Map) { + switch right.mappingType { + case .fromJSON where right.isKeyPresent: + let value: T! = toSignedInteger(right.currentValue) + FromJSON.basicType(&left, object: value) + case .toJSON: + left >>> right + default: () + } +} + + +// MARK: - Unsigned Integer + +/// UnsignedInteger mapping +public func <- (left: inout T, right: Map) { + switch right.mappingType { + case .fromJSON where right.isKeyPresent: + let value: T = toUnsignedInteger(right.currentValue) ?? 0 + FromJSON.basicType(&left, object: value) + case .toJSON: + left >>> right + default: () + } +} + + +/// Optional UnsignedInteger mapping +public func <- (left: inout T?, right: Map) { + switch right.mappingType { + case .fromJSON where right.isKeyPresent: + let value: T? = toUnsignedInteger(right.currentValue) + FromJSON.basicType(&left, object: value) + case .toJSON: + left >>> right + default: () + } +} + +/// ImplicitlyUnwrappedOptional UnsignedInteger mapping +public func <- (left: inout T!, right: Map) { + switch right.mappingType { + case .fromJSON where right.isKeyPresent: + let value: T! = toUnsignedInteger(right.currentValue) + FromJSON.basicType(&left, object: value) + case .toJSON: + left >>> right + default: () + } +} + +// MARK: - Casting Utils + +/// Convert any value to `SignedInteger`. +private func toSignedInteger(_ value: Any?) -> T? { + guard + let value = value, + case let number as NSNumber = value + else { + return nil + } + + 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) { + return T.init(x) + } + 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) { + return T.init(x) + } + if T.self == Int64.self, let x = Int64(exactly: number.int64Value) { + return T.init(x) + } + + return nil +} + +/// Convert any value to `UnsignedInteger`. +private func toUnsignedInteger(_ value: Any?) -> T? { + guard + let value = value, + case let number as NSNumber = value + else { + return nil + } + + 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) { + return T.init(x) + } + 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) { + return T.init(x) + } + if T.self == UInt64.self, let x = UInt64(exactly: number.uint64Value) { + return T.init(x) + } + + return nil +} diff --git a/Example/Pods/ObjectMapper/ObjectMapper/Core/Map.swift b/Example/Pods/ObjectMapper/Sources/Map.swift similarity index 54% rename from Example/Pods/ObjectMapper/ObjectMapper/Core/Map.swift rename to Example/Pods/ObjectMapper/Sources/Map.swift index f01e77a..c7e7a5e 100644 --- a/Example/Pods/ObjectMapper/ObjectMapper/Core/Map.swift +++ b/Example/Pods/ObjectMapper/Sources/Map.swift @@ -6,7 +6,7 @@ // // The MIT License (MIT) // -// Copyright (c) 2014-2015 Hearst +// Copyright (c) 2014-2016 Hearst // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -40,95 +40,89 @@ public final class Map { public internal(set) var JSON: [String: Any] = [:] public internal(set) var isKeyPresent = false - public var currentValue: Any? - public var context: MapContext? - var currentKey: String? + public internal(set) var currentValue: Any? + public internal(set) var currentKey: String? var keyIsNested = false + public internal(set) var nestedKeyDelimiter: String = "." + public var context: MapContext? + public var shouldIncludeNilValues = false /// If this is set to true, toJSON output will include null values for any variables that are not set. - let toObject: Bool // indicates whether the mapping is being applied to an existing object - - /// Counter for failing cases of deserializing values to `let` properties. - private var failedCount: Int = 0 + public let toObject: Bool // indicates whether the mapping is being applied to an existing object - public init(mappingType: MappingType, JSON: [String: Any], toObject: Bool = false, context: MapContext? = nil) { + public init(mappingType: MappingType, JSON: [String: Any], toObject: Bool = false, context: MapContext? = nil, shouldIncludeNilValues: Bool = false) { + self.mappingType = mappingType self.JSON = JSON self.toObject = toObject self.context = context + self.shouldIncludeNilValues = shouldIncludeNilValues } /// Sets the current mapper value and key. /// The Key paramater can be a period separated string (ex. "distance.value") to access sub objects. public subscript(key: String) -> Map { // save key and value associated to it - let nested = key.contains(".") - return self[key, nested: nested, ignoreNil: false] + return self[key, delimiter: ".", ignoreNil: false] + } + + public subscript(key: String, delimiter delimiter: String) -> Map { + let nested = key.contains(delimiter) + return self[key, nested: nested, delimiter: delimiter, ignoreNil: false] } public subscript(key: String, nested nested: Bool) -> Map { - return self[key, nested: nested, ignoreNil: false] + return self[key, nested: nested, delimiter: ".", ignoreNil: false] } - public subscript(key: String, ignoreNil ignoreNil: Bool) -> Map { - let nested = key.contains(".") - return self[key, nested: nested, ignoreNil: ignoreNil] - } - - public subscript(key: String, nested nested: Bool, ignoreNil ignoreNil: Bool) -> Map { - // save key and value associated to it - currentKey = key - keyIsNested = nested - - // check if a value exists for the current key - // do this pre-check for performance reasons - if nested == false { - let object = JSON[key] - let isNSNull = object is NSNull - isKeyPresent = isNSNull ? true : object != nil - currentValue = isNSNull ? nil : object - } else { - // break down the components of the key that are separated by . - (isKeyPresent, currentValue) = valueFor(ArraySlice(key.components(separatedBy: ".")), dictionary: JSON) - } - - // update isKeyPresent if ignoreNil is true - if ignoreNil && currentValue == nil { - isKeyPresent = false - } - - return self + public subscript(key: String, nested nested: Bool, delimiter delimiter: String) -> Map { + return self[key, nested: nested, delimiter: delimiter, ignoreNil: false] } - // MARK: Immutable Mapping + public subscript(key: String, ignoreNil ignoreNil: Bool) -> Map { + return self[key, delimiter: ".", ignoreNil: ignoreNil] + } - public func value() -> T? { - return currentValue as? T + public subscript(key: String, delimiter delimiter: String, ignoreNil ignoreNil: Bool) -> Map { + let nested = key.contains(delimiter) + return self[key, nested: nested, delimiter: delimiter, ignoreNil: ignoreNil] } - public func valueOr( _ defaultValue: @autoclosure() -> T) -> T { - return value() ?? defaultValue() + public subscript(key: String, nested nested: Bool, ignoreNil ignoreNil: Bool) -> Map { + return self[key, nested: nested, delimiter: ".", ignoreNil: ignoreNil] } - /// Returns current JSON value of type `T` if it is existing, or returns a - /// unusable proxy value for `T` and collects failed count. - public func valueOrFail() -> T { - if let value: T = value() { - return value - } else { - // Collects failed count - failedCount += 1 + public subscript(key: String, nested nested: Bool, delimiter delimiter: String, ignoreNil ignoreNil: Bool) -> Map { + // save key and value associated to it + currentKey = key + keyIsNested = nested + nestedKeyDelimiter = delimiter + + if mappingType == .fromJSON { + // check if a value exists for the current key + // do this pre-check for performance reasons + if nested == false { + let object = JSON[key] + let isNSNull = object is NSNull + isKeyPresent = isNSNull ? true : object != nil + currentValue = isNSNull ? nil : object + } else { + // break down the components of the key that are separated by . + (isKeyPresent, currentValue) = valueFor(ArraySlice(key.components(separatedBy: delimiter)), dictionary: JSON) + } - // Returns dummy memory as a proxy for type `T` - let pointer = UnsafeMutablePointer.allocate(capacity: 0) - pointer.deallocate(capacity: 0) - return pointer.pointee + // update isKeyPresent if ignoreNil is true + if ignoreNil && currentValue == nil { + isKeyPresent = false + } } + + return self } - /// Returns whether the receiver is success or failure. - public var isValid: Bool { - return failedCount == 0 + public func value() -> T? { + return currentValue as? T } + } /// Fetch value from JSON dictionary, loop through keyPathComponents until we reach the desired object @@ -142,10 +136,10 @@ private func valueFor(_ keyPathComponents: ArraySlice, dictionary: [Stri let object = dictionary[keyPath] if object is NSNull { return (true, nil) - } else if let dict = object as? [String: Any] , keyPathComponents.count > 1 { + } else if keyPathComponents.count > 1, let dict = object as? [String: Any] { let tail = keyPathComponents.dropFirst() return valueFor(tail, dictionary: dict) - } else if let array = object as? [Any] , keyPathComponents.count > 1 { + } else if keyPathComponents.count > 1, let array = object as? [Any] { let tail = keyPathComponents.dropFirst() return valueFor(tail, array: array) } else { @@ -167,20 +161,20 @@ private func valueFor(_ keyPathComponents: ArraySlice, array: [Any]) -> //Try to convert keypath to Int as index if let keyPath = keyPathComponents.first, let index = Int(keyPath) , index >= 0 && index < array.count { - - let object = array[index] - - if object is NSNull { - return (true, nil) - } else if let array = object as? [Any] , keyPathComponents.count > 1 { - let tail = keyPathComponents.dropFirst() - return valueFor(tail, array: array) - } else if let dict = object as? [String: Any] , keyPathComponents.count > 1 { - let tail = keyPathComponents.dropFirst() - return valueFor(tail, dictionary: dict) - } else { - return (true, object) - } + + let object = array[index] + + if object is NSNull { + return (true, nil) + } else if keyPathComponents.count > 1, let array = object as? [Any] { + let tail = keyPathComponents.dropFirst() + return valueFor(tail, array: array) + } else if keyPathComponents.count > 1, let dict = object as? [String: Any] { + let tail = keyPathComponents.dropFirst() + return valueFor(tail, dictionary: dict) + } else { + return (true, object) + } } return (false, nil) diff --git a/Example/Pods/ObjectMapper/Sources/MapError.swift b/Example/Pods/ObjectMapper/Sources/MapError.swift new file mode 100644 index 0000000..8e1c69a --- /dev/null +++ b/Example/Pods/ObjectMapper/Sources/MapError.swift @@ -0,0 +1,68 @@ +// +// MapError.swift +// ObjectMapper +// +// Created by Tristan Himmelman on 2016-09-26. +// +// The MIT License (MIT) +// +// Copyright (c) 2014-2016 Hearst +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +import Foundation + +public struct MapError: Error { + public var key: String? + public var currentValue: Any? + public var reason: String? + public var file: StaticString? + public var function: StaticString? + public var line: UInt? + + public init(key: String?, currentValue: Any?, reason: String?, file: StaticString? = nil, function: StaticString? = nil, line: UInt? = nil) { + self.key = key + self.currentValue = currentValue + self.reason = reason + self.file = file + self.function = function + self.line = line + } +} + +extension MapError: CustomStringConvertible { + + private var location: String? { + guard let file = file, let function = function, let line = line else { return nil } + let fileName = ((String(describing: file).components(separatedBy: "/").last ?? "").components(separatedBy: ".").first ?? "") + return "\(fileName).\(function):\(line)" + } + + public var description: String { + let info: [(String, Any?)] = [ + ("- reason", reason), + ("- location", location), + ("- key", key), + ("- currentValue", currentValue), + ] + let infoString = info.map { "\($0.0): \($0.1 ?? "nil")" }.joined(separator: "\n") + return "Got an error while mapping.\n\(infoString)" + } + +} diff --git a/Example/Pods/ObjectMapper/ObjectMapper/Core/Mappable.swift b/Example/Pods/ObjectMapper/Sources/Mappable.swift similarity index 66% rename from Example/Pods/ObjectMapper/ObjectMapper/Core/Mappable.swift rename to Example/Pods/ObjectMapper/Sources/Mappable.swift index 18f2ecf..ac5d71d 100644 --- a/Example/Pods/ObjectMapper/ObjectMapper/Core/Mappable.swift +++ b/Example/Pods/ObjectMapper/Sources/Mappable.swift @@ -3,8 +3,28 @@ // ObjectMapper // // Created by Scott Hoyt on 10/25/15. -// Copyright © 2015 hearst. All rights reserved. // +// The MIT License (MIT) +// +// Copyright (c) 2014-2016 Hearst +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. import Foundation @@ -22,7 +42,7 @@ public protocol Mappable: BaseMappable { public protocol StaticMappable: BaseMappable { /// This is function that can be used to: /// 1) provide an existing cached object to be used for mapping - /// 2) return an object of another class (which conforms to Mappable) to be used for mapping. For instance, you may inspect the JSON to infer the type of object that should be used for any given mapping + /// 2) return an object of another class (which conforms to BaseMappable) to be used for mapping. For instance, you may inspect the JSON to infer the type of object that should be used for any given mapping static func objectForMapping(map: Map) -> BaseMappable? } @@ -69,12 +89,9 @@ public extension Array where Element: BaseMappable { } /// Initialize Array from a JSON Array - public init?(JSONArray: [[String: Any]], context: MapContext? = nil) { - if let obj: [Element] = Mapper(context: context).mapArray(JSONArray: JSONArray) { - self = obj - } else { - return nil - } + public init(JSONArray: [[String: Any]], context: MapContext? = nil) { + let obj: [Element] = Mapper(context: context).mapArray(JSONArray: JSONArray) + self = obj } /// Returns the JSON Array diff --git a/Example/Pods/ObjectMapper/ObjectMapper/Core/Mapper.swift b/Example/Pods/ObjectMapper/Sources/Mapper.swift similarity index 80% rename from Example/Pods/ObjectMapper/ObjectMapper/Core/Mapper.swift rename to Example/Pods/ObjectMapper/Sources/Mapper.swift index df02a50..30e7b8b 100755 --- a/Example/Pods/ObjectMapper/ObjectMapper/Core/Mapper.swift +++ b/Example/Pods/ObjectMapper/Sources/Mapper.swift @@ -6,7 +6,7 @@ // // The MIT License (MIT) // -// Copyright (c) 2014-2015 Hearst +// Copyright (c) 2014-2016 Hearst // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -37,9 +37,11 @@ public enum MappingType { public final class Mapper { public var context: MapContext? + public var shouldIncludeNilValues = false /// If this is set to true, toJSON output will include null values for any variables that are not set. - public init(context: MapContext? = nil){ + public init(context: MapContext? = nil, shouldIncludeNilValues: Bool = false){ self.context = context + self.shouldIncludeNilValues = shouldIncludeNilValues } // MARK: Mapping functions that map to an existing object toObject @@ -65,7 +67,7 @@ public final class Mapper { /// Usefull for those pesky objects that have crappy designated initializers like NSManagedObject public func map(JSON: [String: Any], toObject object: N) -> N { var mutableObject = object - let map = Map(mappingType: .fromJSON, JSON: JSON, toObject: true, context: context) + let map = Map(mappingType: .fromJSON, JSON: JSON, toObject: true, context: context, shouldIncludeNilValues: shouldIncludeNilValues) mutableObject.mapping(map: map) return mutableObject } @@ -92,24 +94,39 @@ public final class Mapper { /// Maps a JSON dictionary to an object that conforms to Mappable public func map(JSON: [String: Any]) -> N? { - let map = Map(mappingType: .fromJSON, JSON: JSON, context: context) + let map = Map(mappingType: .fromJSON, JSON: JSON, context: context, shouldIncludeNilValues: shouldIncludeNilValues) - // check if object is StaticMappable - if let klass = N.self as? StaticMappable.Type { + if let klass = N.self as? StaticMappable.Type { // Check if object is StaticMappable if var object = klass.objectForMapping(map: map) as? N { object.mapping(map: map) return object } - } - - // fall back to using init? to create N - if let klass = N.self as? Mappable.Type { + } else if let klass = N.self as? Mappable.Type { // Check if object is Mappable if var object = klass.init(map: map) as? N { object.mapping(map: map) return object } + } else if let klass = N.self as? ImmutableMappable.Type { // Check if object is ImmutableMappable + do { + return try klass.init(map: map) as? N + } catch let error { + #if DEBUG + let exception: NSException + if let mapError = error as? MapError { + exception = NSException(name: .init(rawValue: "MapError"), reason: mapError.description, userInfo: nil) + } else { + exception = NSException(name: .init(rawValue: "ImmutableMappableError"), reason: error.localizedDescription, userInfo: nil) + } + exception.raise() + #else + NSLog("\(error)") + #endif + } + } else { + // Ensure BaseMappable is not implemented directly + assert(false, "BaseMappable should not be implemented directly. Please implement Mappable, StaticMappable or ImmutableMappable") } - + return nil } @@ -142,7 +159,7 @@ public final class Mapper { } /// Maps an array of JSON dictionary to an array of Mappable objects - public func mapArray(JSONArray: [[String: Any]]) -> [N]? { + public func mapArray(JSONArray: [[String: Any]]) -> [N] { // map every element in JSON array to type N let result = JSONArray.flatMap(map) return result @@ -163,7 +180,7 @@ public final class Mapper { return nil } - /// Maps a JSON dictionary of dictionaries to a dictionary of Mappble objects + /// Maps a JSON dictionary of dictionaries to a dictionary of Mappable objects public func mapDictionary(JSON: [String: [String: Any]]) -> [String: N]? { // map every value in dictionary to type N let result = JSON.filterMap(map) @@ -183,7 +200,7 @@ public final class Mapper { return dictionary } - /// Maps a JSON dictionary of dictionaries to an existing dictionary of Mappble objects + /// Maps a JSON dictionary of dictionaries to an existing dictionary of Mappable objects public func mapDictionary(JSON: [String: [String: Any]], toDictionary dictionary: [String: N]) -> [String: N] { var mutableDictionary = dictionary for (key, value) in JSON { @@ -225,9 +242,8 @@ public final class Mapper { if let JSONArray = JSONObject as? [[[String: Any]]] { var objectArray = [[N]]() for innerJSONArray in JSONArray { - if let array = mapArray(JSONArray: innerJSONArray){ - objectArray.append(array) - } + let array = mapArray(JSONArray: innerJSONArray) + objectArray.append(array) } if objectArray.isEmpty == false { @@ -264,6 +280,44 @@ public final class Mapper { } } +extension Mapper { + // MARK: Functions that create model from JSON file + + /// JSON file to Mappable object + /// - parameter JSONfile: Filename + /// - Returns: Mappable object + public func map(JSONfile: String) -> N? { + if let path = Bundle.main.path(forResource: JSONfile, ofType: nil) { + do { + let JSONString = try String(contentsOfFile: path) + do { + return self.map(JSONString: JSONString) + } + } catch { + return nil + } + } + return nil + } + + /// JSON file to Mappable object array + /// - parameter JSONfile: Filename + /// - Returns: Mappable object array + public func mapArray(JSONfile: String) -> [N]? { + if let path = Bundle.main.path(forResource: JSONfile, ofType: nil) { + do { + let JSONString = try String(contentsOfFile: path) + do { + return self.mapArray(JSONString: JSONString) + } + } catch { + return nil + } + } + return nil + } +} + extension Mapper { // MARK: Functions that create JSON from objects @@ -271,7 +325,7 @@ extension Mapper { ///Maps an object that conforms to Mappable to a JSON dictionary public func toJSON(_ object: N) -> [String: Any] { var mutableObject = object - let map = Map(mappingType: .toJSON, JSON: [:], context: context) + let map = Map(mappingType: .toJSON, JSON: [:], context: context, shouldIncludeNilValues: shouldIncludeNilValues) mutableObject.mapping(map: map) return map.JSON } @@ -286,17 +340,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)) } } @@ -393,22 +447,22 @@ extension Mapper where N: Hashable { } extension Dictionary { - internal func map(_ f: (Element) -> (K, V)) -> [K: V] { + internal func map(_ f: (Element) throws -> (K, V)) rethrows -> [K: V] { var mapped = [K: V]() for element in self { - let newElement = f(element) + let newElement = try f(element) mapped[newElement.0] = newElement.1 } return mapped } - internal func map(_ f: (Element) -> (K, [V])) -> [K: [V]] { + internal func map(_ f: (Element) throws -> (K, [V])) rethrows -> [K: [V]] { var mapped = [K: [V]]() for element in self { - let newElement = f(element) + let newElement = try f(element) mapped[newElement.0] = newElement.1 } @@ -416,11 +470,11 @@ extension Dictionary { } - internal func filterMap(_ f: (Value) -> U?) -> [Key: U] { + internal func filterMap(_ f: (Value) throws -> U?) rethrows -> [Key: U] { var mapped = [Key: U]() for (key, value) in self { - if let newValue = f(value) { + if let newValue = try f(value) { mapped[key] = newValue } } diff --git a/Example/Pods/ObjectMapper/ObjectMapper/Transforms/NSDecimalNumberTransform.swift b/Example/Pods/ObjectMapper/Sources/NSDecimalNumberTransform.swift similarity index 80% rename from Example/Pods/ObjectMapper/ObjectMapper/Transforms/NSDecimalNumberTransform.swift rename to Example/Pods/ObjectMapper/Sources/NSDecimalNumberTransform.swift index c4ad974..5852135 100644 --- a/Example/Pods/ObjectMapper/ObjectMapper/Transforms/NSDecimalNumberTransform.swift +++ b/Example/Pods/ObjectMapper/Sources/NSDecimalNumberTransform.swift @@ -6,7 +6,7 @@ // // The MIT License (MIT) // -// Copyright (c) 2014-2015 Hearst +// Copyright (c) 2014-2016 Hearst // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -34,17 +34,18 @@ open class NSDecimalNumberTransform: TransformType { public init() {} - public func transformFromJSON(_ value: Any?) -> NSDecimalNumber? { + open func transformFromJSON(_ value: Any?) -> NSDecimalNumber? { if let string = value as? String { return NSDecimalNumber(string: string) - } - if let double = value as? Double { - return NSDecimalNumber(value: double) + } else if let number = value as? NSNumber { + return NSDecimalNumber(decimal: number.decimalValue) + } else if let double = value as? Double { + return NSDecimalNumber(floatLiteral: double) } return nil } - public func transformToJSON(_ value: NSDecimalNumber?) -> String? { + open func transformToJSON(_ value: NSDecimalNumber?) -> String? { guard let value = value else { return nil } return value.description } diff --git a/Example/Pods/ObjectMapper/Sources/Operators.swift b/Example/Pods/ObjectMapper/Sources/Operators.swift new file mode 100755 index 0000000..eb49735 --- /dev/null +++ b/Example/Pods/ObjectMapper/Sources/Operators.swift @@ -0,0 +1,377 @@ +// +// Operators.swift +// ObjectMapper +// +// Created by Tristan Himmelman on 2014-10-09. +// +// The MIT License (MIT) +// +// Copyright (c) 2014-2016 Hearst +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +/** +* This file defines a new operator which is used to create a mapping between an object and a JSON key value. +* There is an overloaded operator definition for each type of object that is supported in ObjectMapper. +* This provides a way to add custom logic to handle specific types of objects +*/ + +/// Operator used for defining mappings to and from JSON +infix operator <- + +/// Operator used to define mappings to JSON +infix operator >>> + +// MARK:- Objects with Basic types + +/// Object of Basic type +public func <- (left: inout T, right: Map) { + switch right.mappingType { + case .fromJSON where right.isKeyPresent: + FromJSON.basicType(&left, object: right.value()) + case .toJSON: + left >>> right + default: () + } +} + +public func >>> (left: T, right: Map) { + if right.mappingType == .toJSON { + ToJSON.basicType(left, map: right) + } +} + + +/// Optional object of basic type +public func <- (left: inout T?, right: Map) { + switch right.mappingType { + case .fromJSON where right.isKeyPresent: + FromJSON.optionalBasicType(&left, object: right.value()) + case .toJSON: + left >>> right + default: () + } +} + +public func >>> (left: T?, right: Map) { + if right.mappingType == .toJSON { + ToJSON.optionalBasicType(left, map: right) + } +} + + +/// Implicitly unwrapped optional object of basic type +public func <- (left: inout T!, right: Map) { + switch right.mappingType { + case .fromJSON where right.isKeyPresent: + FromJSON.optionalBasicType(&left, object: right.value()) + case .toJSON: + left >>> right + default: () + } +} + +// MARK:- Mappable Objects - + +/// Object conforming to Mappable +public func <- (left: inout T, right: Map) { + switch right.mappingType { + case .fromJSON: + FromJSON.object(&left, map: right) + case .toJSON: + left >>> right + } +} + +public func >>> (left: T, right: Map) { + if right.mappingType == .toJSON { + ToJSON.object(left, map: right) + } +} + + +/// Optional Mappable objects +public func <- (left: inout T?, right: Map) { + switch right.mappingType { + case .fromJSON where right.isKeyPresent: + FromJSON.optionalObject(&left, map: right) + case .toJSON: + left >>> right + default: () + } +} + +public func >>> (left: T?, right: Map) { + if right.mappingType == .toJSON { + ToJSON.optionalObject(left, map: right) + } +} + + +/// Implicitly unwrapped optional Mappable objects +public func <- (left: inout T!, right: Map) { + switch right.mappingType { + case .fromJSON where right.isKeyPresent: + FromJSON.optionalObject(&left, map: right) + case .toJSON: + left >>> right + default: () + } +} + +// MARK:- Dictionary of Mappable objects - Dictionary + +/// Dictionary of Mappable objects +public func <- (left: inout Dictionary, right: Map) { + switch right.mappingType { + case .fromJSON where right.isKeyPresent: + FromJSON.objectDictionary(&left, map: right) + case .toJSON: + left >>> right + default: () + } +} + +public func >>> (left: Dictionary, right: Map) { + if right.mappingType == .toJSON { + ToJSON.objectDictionary(left, map: right) + } +} + + +/// Optional Dictionary of Mappable object +public func <- (left: inout Dictionary?, right: Map) { + switch right.mappingType { + case .fromJSON where right.isKeyPresent: + FromJSON.optionalObjectDictionary(&left, map: right) + case .toJSON: + left >>> right + default: () + } +} + +public func >>> (left: Dictionary?, right: Map) { + if right.mappingType == .toJSON { + ToJSON.optionalObjectDictionary(left, map: right) + } +} + + +/// Implicitly unwrapped Optional Dictionary of Mappable object +public func <- (left: inout Dictionary!, right: Map) { + switch right.mappingType { + case .fromJSON where right.isKeyPresent: + FromJSON.optionalObjectDictionary(&left, map: right) + case .toJSON: + left >>> right + default: () + } +} + +/// Dictionary of Mappable objects +public func <- (left: inout Dictionary, right: Map) { + switch right.mappingType { + case .fromJSON where right.isKeyPresent: + FromJSON.objectDictionaryOfArrays(&left, map: right) + case .toJSON: + left >>> right + default: () + } +} + +public func >>> (left: Dictionary, right: Map) { + if right.mappingType == .toJSON { + ToJSON.objectDictionaryOfArrays(left, map: right) + } +} + +/// Optional Dictionary of Mappable object +public func <- (left: inout Dictionary?, right: Map) { + switch right.mappingType { + case .fromJSON where right.isKeyPresent: + FromJSON.optionalObjectDictionaryOfArrays(&left, map: right) + case .toJSON: + left >>> right + default: () + } +} + +public func >>> (left: Dictionary?, right: Map) { + if right.mappingType == .toJSON { + ToJSON.optionalObjectDictionaryOfArrays(left, map: right) + } +} + + +/// Implicitly unwrapped Optional Dictionary of Mappable object +public func <- (left: inout Dictionary!, right: Map) { + switch right.mappingType { + case .fromJSON where right.isKeyPresent: + FromJSON.optionalObjectDictionaryOfArrays(&left, map: right) + case .toJSON: + left >>> right + default: () + } +} + +// MARK:- Array of Mappable objects - Array + +/// Array of Mappable objects +public func <- (left: inout Array, right: Map) { + switch right.mappingType { + case .fromJSON where right.isKeyPresent: + FromJSON.objectArray(&left, map: right) + case .toJSON: + left >>> right + default: () + } +} + +public func >>> (left: Array, right: Map) { + if right.mappingType == .toJSON { + ToJSON.objectArray(left, map: right) + } +} + +/// Optional array of Mappable objects +public func <- (left: inout Array?, right: Map) { + switch right.mappingType { + case .fromJSON where right.isKeyPresent: + FromJSON.optionalObjectArray(&left, map: right) + case .toJSON: + left >>> right + default: () + } +} + +public func >>> (left: Array?, right: Map) { + if right.mappingType == .toJSON { + ToJSON.optionalObjectArray(left, map: right) + } +} + + +/// Implicitly unwrapped Optional array of Mappable objects +public func <- (left: inout Array!, right: Map) { + switch right.mappingType { + case .fromJSON where right.isKeyPresent: + FromJSON.optionalObjectArray(&left, map: right) + case .toJSON: + left >>> right + default: () + } +} + +// MARK:- Array of Array of Mappable objects - Array> + +/// Array of Array Mappable objects +public func <- (left: inout Array>, right: Map) { + switch right.mappingType { + case .fromJSON where right.isKeyPresent: + FromJSON.twoDimensionalObjectArray(&left, map: right) + case .toJSON: + left >>> right + default: () + } +} + +public func >>> (left: Array>, right: Map) { + if right.mappingType == .toJSON { + ToJSON.twoDimensionalObjectArray(left, map: right) + } +} + + +/// Optional array of Mappable objects +public func <- (left:inout Array>?, right: Map) { + switch right.mappingType { + case .fromJSON where right.isKeyPresent: + FromJSON.optionalTwoDimensionalObjectArray(&left, map: right) + case .toJSON: + left >>> right + default: () + } +} + +public func >>> (left: Array>?, right: Map) { + if right.mappingType == .toJSON { + ToJSON.optionalTwoDimensionalObjectArray(left, map: right) + } +} + + +/// Implicitly unwrapped Optional array of Mappable objects +public func <- (left: inout Array>!, right: Map) { + switch right.mappingType { + case .fromJSON where right.isKeyPresent: + FromJSON.optionalTwoDimensionalObjectArray(&left, map: right) + case .toJSON: + left >>> right + default: () + } +} + +// MARK:- Set of Mappable objects - Set + +/// Set of Mappable objects +public func <- (left: inout Set, right: Map) { + switch right.mappingType { + case .fromJSON where right.isKeyPresent: + FromJSON.objectSet(&left, map: right) + case .toJSON: + left >>> right + default: () + } +} + +public func >>> (left: Set, right: Map) { + if right.mappingType == .toJSON { + ToJSON.objectSet(left, map: right) + } +} + + +/// Optional Set of Mappable objects +public func <- (left: inout Set?, right: Map) { + switch right.mappingType { + case .fromJSON where right.isKeyPresent: + FromJSON.optionalObjectSet(&left, map: right) + case .toJSON: + left >>> right + default: () + } +} + +public func >>> (left: Set?, right: Map) { + if right.mappingType == .toJSON { + ToJSON.optionalObjectSet(left, map: right) + } +} + + +/// Implicitly unwrapped Optional Set of Mappable objects +public func <- (left: inout Set!, right: Map) { + switch right.mappingType { + case .fromJSON where right.isKeyPresent: + FromJSON.optionalObjectSet(&left, map: right) + case .toJSON: + left >>> right + default: () + } +} diff --git a/Example/Pods/ObjectMapper/ObjectMapper/Core/ToJSON.swift b/Example/Pods/ObjectMapper/Sources/ToJSON.swift similarity index 77% rename from Example/Pods/ObjectMapper/ObjectMapper/Core/ToJSON.swift rename to Example/Pods/ObjectMapper/Sources/ToJSON.swift index 65966ad..bb53f61 100644 --- a/Example/Pods/ObjectMapper/ObjectMapper/Core/ToJSON.swift +++ b/Example/Pods/ObjectMapper/Sources/ToJSON.swift @@ -6,7 +6,7 @@ // // The MIT License (MIT) // -// Copyright (c) 2014-2015 Hearst +// Copyright (c) 2014-2016 Hearst // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -26,22 +26,22 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -import class Foundation.NSNumber +import Foundation private func setValue(_ value: Any, map: Map) { - setValue(value, key: map.currentKey!, checkForNestedKeys: map.keyIsNested, dictionary: &map.JSON) + setValue(value, key: map.currentKey!, checkForNestedKeys: map.keyIsNested, delimiter: map.nestedKeyDelimiter, dictionary: &map.JSON) } -private func setValue(_ value: Any, key: String, checkForNestedKeys: Bool, dictionary: inout [String : Any]) { +private func setValue(_ value: Any, key: String, checkForNestedKeys: Bool, delimiter: String, dictionary: inout [String : Any]) { if checkForNestedKeys { - let keyComponents = ArraySlice(key.characters.split { $0 == "." }) + let keyComponents = ArraySlice(key.components(separatedBy: delimiter).filter { !$0.isEmpty }.map { $0 }) setValue(value, forKeyPathComponents: keyComponents, dictionary: &dictionary) } else { dictionary[key] = value } } -private func setValue(_ value: Any, forKeyPathComponents components: ArraySlice, dictionary: inout [String : Any]) { +private func setValue(_ value: Any, forKeyPathComponents components: ArraySlice, dictionary: inout [String : Any]) { if components.isEmpty { return } @@ -73,6 +73,7 @@ internal final class ToJSON { || x is Double || x is Float || x is String + || x is NSNull || x is Array // Arrays || x is Array || x is Array @@ -92,15 +93,17 @@ internal final class ToJSON { setValue(x, map: map) } } - + class func optionalBasicType(_ field: N?, map: Map) { if let field = field { basicType(field, map: map) + } else if map.shouldIncludeNilValues { + basicType(NSNull(), map: map) //If BasicType is nil, emil NSNull into the JSON output } } class func object(_ field: N, map: Map) { - if let result = Mapper(context: map.context).toJSON(field) as Any? { + if let result = Mapper(context: map.context, shouldIncludeNilValues: map.shouldIncludeNilValues).toJSON(field) as Any? { setValue(result, map: map) } } @@ -112,7 +115,7 @@ internal final class ToJSON { } class func objectArray(_ field: Array, map: Map) { - let JSONObjects = Mapper(context: map.context).toJSONArray(field) + let JSONObjects = Mapper(context: map.context, shouldIncludeNilValues: map.shouldIncludeNilValues).toJSONArray(field) setValue(JSONObjects, map: map) } @@ -126,7 +129,7 @@ internal final class ToJSON { class func twoDimensionalObjectArray(_ field: Array>, map: Map) { var array = [[[String: Any]]]() for innerArray in field { - let JSONObjects = Mapper(context: map.context).toJSONArray(innerArray) + let JSONObjects = Mapper(context: map.context, shouldIncludeNilValues: map.shouldIncludeNilValues).toJSONArray(innerArray) array.append(JSONObjects) } setValue(array, map: map) @@ -138,32 +141,32 @@ internal final class ToJSON { } } - class func objectSet(_ field: Set, map: Map) where N: Hashable { - let JSONObjects = Mapper(context: map.context).toJSONSet(field) + class func objectSet(_ field: Set, map: Map) { + let JSONObjects = Mapper(context: map.context, shouldIncludeNilValues: map.shouldIncludeNilValues).toJSONSet(field) setValue(JSONObjects, map: map) } - class func optionalObjectSet(_ field: Set?, map: Map) where N: Hashable { + class func optionalObjectSet(_ field: Set?, map: Map) { if let field = field { objectSet(field, map: map) } } class func objectDictionary(_ field: Dictionary, map: Map) { - let JSONObjects = Mapper(context: map.context).toJSONDictionary(field) + let JSONObjects = Mapper(context: map.context, shouldIncludeNilValues: map.shouldIncludeNilValues).toJSONDictionary(field) setValue(JSONObjects, map: map) } - + class func optionalObjectDictionary(_ field: Dictionary?, map: Map) { - if let field = field { + if let field = field { objectDictionary(field, map: map) - } - } - + } + } + class func objectDictionaryOfArrays(_ field: Dictionary, map: Map) { - let JSONObjects = Mapper(context: map.context).toJSONDictionaryOfArrays(field) + let JSONObjects = Mapper(context: map.context, shouldIncludeNilValues: map.shouldIncludeNilValues).toJSONDictionaryOfArrays(field) setValue(JSONObjects, map: map) } diff --git a/Example/Pods/ObjectMapper/ObjectMapper/Transforms/TransformOf.swift b/Example/Pods/ObjectMapper/Sources/TransformOf.swift similarity index 91% rename from Example/Pods/ObjectMapper/ObjectMapper/Transforms/TransformOf.swift rename to Example/Pods/ObjectMapper/Sources/TransformOf.swift index 2a53f17..97056c6 100644 --- a/Example/Pods/ObjectMapper/ObjectMapper/Transforms/TransformOf.swift +++ b/Example/Pods/ObjectMapper/Sources/TransformOf.swift @@ -6,7 +6,7 @@ // // The MIT License (MIT) // -// Copyright (c) 2014-2015 Hearst +// Copyright (c) 2014-2016 Hearst // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -38,11 +38,11 @@ open class TransformOf: TransformType { self.toJSON = toJSON } - public func transformFromJSON(_ value: Any?) -> ObjectType? { + open func transformFromJSON(_ value: Any?) -> ObjectType? { return fromJSON(value as? JSONType) } - public func transformToJSON(_ value: ObjectType?) -> JSONType? { + open func transformToJSON(_ value: ObjectType?) -> JSONType? { return toJSON(value) } } diff --git a/Example/Pods/ObjectMapper/Sources/TransformOperators.swift b/Example/Pods/ObjectMapper/Sources/TransformOperators.swift new file mode 100644 index 0000000..0a96e00 --- /dev/null +++ b/Example/Pods/ObjectMapper/Sources/TransformOperators.swift @@ -0,0 +1,620 @@ +// +// TransformOperators.swift +// ObjectMapper +// +// Created by Tristan Himmelman on 2016-09-26. +// Copyright © 2016 hearst. All rights reserved. +// + +import Foundation + +// MARK:- Transforms + +/// Object of Basic type with Transform +public func <- (left: inout Transform.Object, right: (Map, Transform)) { + let (map, transform) = right + switch map.mappingType { + case .fromJSON where map.isKeyPresent: + let value = transform.transformFromJSON(map.currentValue) + FromJSON.basicType(&left, object: value) + case .toJSON: + left >>> right + default: () + } +} + +public func >>> (left: Transform.Object, right: (Map, Transform)) { + let (map, transform) = right + if map.mappingType == .toJSON { + let value: Transform.JSON? = transform.transformToJSON(left) + ToJSON.optionalBasicType(value, map: map) + } +} + + +/// Optional object of basic type with Transform +public func <- (left: inout Transform.Object?, right: (Map, Transform)) { + let (map, transform) = right + switch map.mappingType { + case .fromJSON where map.isKeyPresent: + let value = transform.transformFromJSON(map.currentValue) + FromJSON.optionalBasicType(&left, object: value) + case .toJSON: + left >>> right + default: () + } +} + +public func >>> (left: Transform.Object?, right: (Map, Transform)) { + let (map, transform) = right + if map.mappingType == .toJSON { + let value: Transform.JSON? = transform.transformToJSON(left) + ToJSON.optionalBasicType(value, map: map) + } +} + + +/// Implicitly unwrapped optional object of basic type with Transform +public func <- (left: inout Transform.Object!, right: (Map, Transform)) { + let (map, transform) = right + switch map.mappingType { + case .fromJSON where map.isKeyPresent: + let value = transform.transformFromJSON(map.currentValue) + FromJSON.optionalBasicType(&left, object: value) + case .toJSON: + left >>> right + default: () + } +} + +/// Array of Basic type with Transform +public func <- (left: inout [Transform.Object], right: (Map, Transform)) { + let (map, transform) = right + switch map.mappingType { + case .fromJSON where map.isKeyPresent: + let values = fromJSONArrayWithTransform(map.currentValue, transform: transform) + FromJSON.basicType(&left, object: values) + case .toJSON: + left >>> right + default: () + } +} + +public func >>> (left: [Transform.Object], right: (Map, Transform)) { + let (map, transform) = right + if map.mappingType == .toJSON{ + let values = toJSONArrayWithTransform(left, transform: transform) + ToJSON.optionalBasicType(values, map: map) + } +} + + +/// Optional array of Basic type with Transform +public func <- (left: inout [Transform.Object]?, right: (Map, Transform)) { + let (map, transform) = right + switch map.mappingType { + case .fromJSON where map.isKeyPresent: + let values = fromJSONArrayWithTransform(map.currentValue, transform: transform) + FromJSON.optionalBasicType(&left, object: values) + case .toJSON: + left >>> right + default: () + } +} + +public func >>> (left: [Transform.Object]?, right: (Map, Transform)) { + let (map, transform) = right + if map.mappingType == .toJSON { + let values = toJSONArrayWithTransform(left, transform: transform) + ToJSON.optionalBasicType(values, map: map) + } +} + + +/// Implicitly unwrapped optional array of Basic type with Transform +public func <- (left: inout [Transform.Object]!, right: (Map, Transform)) { + let (map, transform) = right + switch map.mappingType { + case .fromJSON where map.isKeyPresent: + let values = fromJSONArrayWithTransform(map.currentValue, transform: transform) + FromJSON.optionalBasicType(&left, object: values) + case .toJSON: + left >>> right + default: () + } +} + +/// Dictionary of Basic type with Transform +public func <- (left: inout [String: Transform.Object], right: (Map, Transform)) { + let (map, transform) = right + switch map.mappingType { + case .fromJSON where map.isKeyPresent: + let values = fromJSONDictionaryWithTransform(map.currentValue, transform: transform) + FromJSON.basicType(&left, object: values) + case .toJSON: + left >>> right + default: () + } +} + +public func >>> (left: [String: Transform.Object], right: (Map, Transform)) { + let (map, transform) = right + if map.mappingType == . toJSON { + let values = toJSONDictionaryWithTransform(left, transform: transform) + ToJSON.optionalBasicType(values, map: map) + } +} + + +/// Optional dictionary of Basic type with Transform +public func <- (left: inout [String: Transform.Object]?, right: (Map, Transform)) { + let (map, transform) = right + switch map.mappingType { + case .fromJSON where map.isKeyPresent: + let values = fromJSONDictionaryWithTransform(map.currentValue, transform: transform) + FromJSON.optionalBasicType(&left, object: values) + case .toJSON: + left >>> right + default: () + } +} + +public func >>> (left: [String: Transform.Object]?, right: (Map, Transform)) { + let (map, transform) = right + if map.mappingType == .toJSON { + let values = toJSONDictionaryWithTransform(left, transform: transform) + ToJSON.optionalBasicType(values, map: map) + } +} + + +/// Implicitly unwrapped optional dictionary of Basic type with Transform +public func <- (left: inout [String: Transform.Object]!, right: (Map, Transform)) { + let (map, transform) = right + switch map.mappingType { + case .fromJSON where map.isKeyPresent: + let values = fromJSONDictionaryWithTransform(map.currentValue, transform: transform) + FromJSON.optionalBasicType(&left, object: values) + case .toJSON: + left >>> right + default: () + } +} + +// MARK:- Transforms of Mappable Objects - + +/// Object conforming to Mappable that have transforms +public func <- (left: inout Transform.Object, right: (Map, Transform)) where Transform.Object: BaseMappable { + let (map, transform) = right + switch map.mappingType { + case .fromJSON where map.isKeyPresent: + let value: Transform.Object? = transform.transformFromJSON(map.currentValue) + FromJSON.basicType(&left, object: value) + case .toJSON: + left >>> right + default: () + } +} + +public func >>> (left: Transform.Object, right: (Map, Transform)) where Transform.Object: BaseMappable { + let (map, transform) = right + if map.mappingType == .toJSON { + let value: Transform.JSON? = transform.transformToJSON(left) + ToJSON.optionalBasicType(value, map: map) + } +} + + +/// Optional Mappable objects that have transforms +public func <- (left: inout Transform.Object?, right: (Map, Transform)) where Transform.Object: BaseMappable { + let (map, transform) = right + switch map.mappingType { + case .fromJSON where map.isKeyPresent: + let value: Transform.Object? = transform.transformFromJSON(map.currentValue) + FromJSON.optionalBasicType(&left, object: value) + case .toJSON: + left >>> right + default: () + } +} + +public func >>> (left: Transform.Object?, right: (Map, Transform)) where Transform.Object: BaseMappable { + let (map, transform) = right + if map.mappingType == .toJSON{ + let value: Transform.JSON? = transform.transformToJSON(left) + ToJSON.optionalBasicType(value, map: map) + } +} + + +/// 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 + switch map.mappingType { + case .fromJSON where map.isKeyPresent: + let value: Transform.Object? = transform.transformFromJSON(map.currentValue) + FromJSON.optionalBasicType(&left, object: value) + case .toJSON: + left >>> right + default: () + } +} + + +// MARK:- Dictionary of Mappable objects with a transform - Dictionary + +/// Dictionary of Mappable objects with a transform +public func <- (left: inout Dictionary, right: (Map, Transform)) where Transform.Object: BaseMappable { + let (map, transform) = right + if map.mappingType == .fromJSON && map.isKeyPresent, + let object = map.currentValue as? [String: Any] { + let value = fromJSONDictionaryWithTransform(object as Any?, transform: transform) ?? left + FromJSON.basicType(&left, object: value) + } else if map.mappingType == .toJSON { + left >>> right + } +} + +public func >>> (left: Dictionary, right: (Map, Transform)) where Transform.Object: BaseMappable { + let (map, transform) = right + if map.mappingType == .toJSON { + let value = toJSONDictionaryWithTransform(left, transform: transform) + ToJSON.basicType(value, map: map) + } +} + + +/// Optional Dictionary of Mappable object with a transform +public func <- (left: inout Dictionary?, right: (Map, Transform)) where Transform.Object: BaseMappable { + let (map, transform) = right + if map.mappingType == .fromJSON && map.isKeyPresent, let object = map.currentValue as? [String : Any]{ + let value = fromJSONDictionaryWithTransform(object as Any?, transform: transform) ?? left + FromJSON.optionalBasicType(&left, object: value) + } else if map.mappingType == .toJSON { + left >>> right + } +} + +public func >>> (left: Dictionary?, right: (Map, Transform)) where Transform.Object: BaseMappable { + let (map, transform) = right + if map.mappingType == .toJSON { + let value = toJSONDictionaryWithTransform(left, transform: transform) + ToJSON.optionalBasicType(value, map: map) + } +} + + +/// 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 + if map.mappingType == .fromJSON && map.isKeyPresent, let dictionary = map.currentValue as? [String : Any]{ + let transformedDictionary = fromJSONDictionaryWithTransform(dictionary as Any?, transform: transform) ?? left + FromJSON.optionalBasicType(&left, object: transformedDictionary) + } else if map.mappingType == .toJSON { + left >>> right + } +} + +/// Dictionary of Mappable objects with a transform +public func <- (left: inout Dictionary, right: (Map, Transform)) where Transform.Object: BaseMappable { + let (map, transform) = right + + if let dictionary = map.currentValue as? [String : [Any]], map.mappingType == .fromJSON && map.isKeyPresent { + let transformedDictionary = dictionary.map { (arg: (key: String, values: [Any])) -> (String, [Transform.Object]) in + let (key, values) = arg + if let jsonArray = fromJSONArrayWithTransform(values, transform: transform) { + return (key, jsonArray) + } + if let leftValue = left[key] { + return (key, leftValue) + } + return (key, []) + } + + FromJSON.basicType(&left, object: transformedDictionary) + } else if map.mappingType == .toJSON { + left >>> right + } +} + +public func >>> (left: Dictionary, right: (Map, Transform)) where Transform.Object: BaseMappable { + let (map, transform) = right + + if map.mappingType == .toJSON { + + let transformedDictionary = left.map { (arg: (key: String, value: [Transform.Object])) in + return (arg.key, toJSONArrayWithTransform(arg.value, transform: transform) ?? []) + } + + ToJSON.basicType(transformedDictionary, map: map) + } +} + + +/// Optional Dictionary of Mappable object with a transform +public func <- (left: inout Dictionary?, right: (Map, Transform)) where Transform.Object: BaseMappable { + let (map, transform) = right + + if let dictionary = map.currentValue as? [String : [Any]], map.mappingType == .fromJSON && map.isKeyPresent { + + let transformedDictionary = dictionary.map { (arg: (key: String, values: [Any])) -> (String, [Transform.Object]) in + let (key, values) = arg + if let jsonArray = fromJSONArrayWithTransform(values, transform: transform) { + return (key, jsonArray) + } + if let leftValue = left?[key] { + return (key, leftValue) + } + return (key, []) + } + + FromJSON.optionalBasicType(&left, object: transformedDictionary) + } else if map.mappingType == .toJSON { + left >>> right + } +} + +public func >>> (left: Dictionary?, right: (Map, Transform)) where Transform.Object: BaseMappable { + let (map, transform) = right + + if map.mappingType == .toJSON { + let transformedDictionary = left?.map { (arg: (key: String, values: [Transform.Object])) in + return (arg.key, toJSONArrayWithTransform(arg.values, transform: transform) ?? []) + } + + ToJSON.optionalBasicType(transformedDictionary, map: map) + } +} + + +/// 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 + + if let dictionary = map.currentValue as? [String : [Any]], map.mappingType == .fromJSON && map.isKeyPresent { + let transformedDictionary = dictionary.map { (arg: (key: String, values: [Any])) -> (String, [Transform.Object]) in + let (key, values) = arg + if let jsonArray = fromJSONArrayWithTransform(values, transform: transform) { + return (key, jsonArray) + } + if let leftValue = left?[key] { + return (key, leftValue) + } + return (key, []) + } + FromJSON.optionalBasicType(&left, object: transformedDictionary) + } else if map.mappingType == .toJSON { + left >>> right + } +} + +// MARK:- Array of Mappable objects with transforms - Array + +/// Array of Mappable objects +public func <- (left: inout Array, right: (Map, Transform)) where Transform.Object: BaseMappable { + let (map, transform) = right + switch map.mappingType { + case .fromJSON where map.isKeyPresent: + if let transformedValues = fromJSONArrayWithTransform(map.currentValue, transform: transform) { + FromJSON.basicType(&left, object: transformedValues) + } + case .toJSON: + left >>> right + default: () + } +} + +public func >>> (left: Array, right: (Map, Transform)) where Transform.Object: BaseMappable { + let (map, transform) = right + if map.mappingType == .toJSON { + let transformedValues = toJSONArrayWithTransform(left, transform: transform) + ToJSON.optionalBasicType(transformedValues, map: map) + } +} + + +/// Optional array of Mappable objects +public func <- (left: inout Array?, right: (Map, Transform)) where Transform.Object: BaseMappable { + let (map, transform) = right + switch map.mappingType { + case .fromJSON where map.isKeyPresent: + let transformedValues = fromJSONArrayWithTransform(map.currentValue, transform: transform) + FromJSON.optionalBasicType(&left, object: transformedValues) + case .toJSON: + left >>> right + default: () + } +} + +public func >>> (left: Array?, right: (Map, Transform)) where Transform.Object: BaseMappable { + let (map, transform) = right + if map.mappingType == .toJSON { + let transformedValues = toJSONArrayWithTransform(left, transform: transform) + ToJSON.optionalBasicType(transformedValues, map: map) + } +} + + +/// Implicitly unwrapped Optional array of Mappable objects +public func <- (left: inout Array!, right: (Map, Transform)) where Transform.Object: BaseMappable { + let (map, transform) = right + switch map.mappingType { + case .fromJSON where map.isKeyPresent: + let transformedValues = fromJSONArrayWithTransform(map.currentValue, transform: transform) + FromJSON.optionalBasicType(&left, object: transformedValues) + case .toJSON: + left >>> right + default: () + } +} + +// MARK:- Array of Array of objects - Array>> with transforms + +/// Array of Array of objects with transform +public func <- (left: inout [[Transform.Object]], right: (Map, Transform)) { + let (map, transform) = right + switch map.mappingType { + case .toJSON: + left >>> right + case .fromJSON where map.isKeyPresent: + guard let original2DArray = map.currentValue as? [[Any]] else { break } + let transformed2DArray = original2DArray.flatMap { values in + fromJSONArrayWithTransform(values as Any?, transform: transform) + } + FromJSON.basicType(&left, object: transformed2DArray) + default: + break + } +} + +public func >>> (left: [[Transform.Object]], right: (Map, Transform)) { + let (map, transform) = right + if map.mappingType == .toJSON{ + let transformed2DArray = left.flatMap { values in + toJSONArrayWithTransform(values, transform: transform) + } + ToJSON.basicType(transformed2DArray, map: map) + } +} + +/// Optional array of array of objects with transform +public func <- (left: inout [[Transform.Object]]?, right: (Map, Transform)) { + let (map, transform) = right + switch map.mappingType { + case .toJSON: + left >>> right + case .fromJSON where map.isKeyPresent: + guard let original2DArray = map.currentValue as? [[Any]] else { break } + let transformed2DArray = original2DArray.flatMap { values in + fromJSONArrayWithTransform(values as Any?, transform: transform) + } + FromJSON.optionalBasicType(&left, object: transformed2DArray) + default: + break + } +} + +public func >>> (left: [[Transform.Object]]?, right: (Map, Transform)) { + let (map, transform) = right + if map.mappingType == .toJSON { + let transformed2DArray = left?.flatMap { values in + toJSONArrayWithTransform(values, transform: transform) + } + ToJSON.optionalBasicType(transformed2DArray, map: map) + } +} + + +/// 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 { + case .toJSON: + left >>> right + case .fromJSON where map.isKeyPresent: + guard let original2DArray = map.currentValue as? [[Any]] else { break } + let transformed2DArray = original2DArray.flatMap { values in + fromJSONArrayWithTransform(values as Any?, transform: transform) + } + FromJSON.optionalBasicType(&left, object: transformed2DArray) + default: + break + } +} + +// MARK:- Set of Mappable objects with a transform - Set + +/// Set of Mappable objects with transform +public func <- (left: inout Set, right: (Map, Transform)) where Transform.Object: BaseMappable { + let (map, transform) = right + switch map.mappingType { + case .fromJSON where map.isKeyPresent: + if let transformedValues = fromJSONArrayWithTransform(map.currentValue, transform: transform) { + FromJSON.basicType(&left, object: Set(transformedValues)) + } + case .toJSON: + left >>> right + default: () + } +} + +public func >>> (left: Set, right: (Map, Transform)) where Transform.Object: BaseMappable { + let (map, transform) = right + if map.mappingType == .toJSON { + let transformedValues = toJSONArrayWithTransform(Array(left), transform: transform) + ToJSON.optionalBasicType(transformedValues, map: map) + } +} + + +/// Optional Set of Mappable objects with transform +public func <- (left: inout Set?, right: (Map, Transform)) where Transform.Object: BaseMappable { + let (map, transform) = right + switch map.mappingType { + case .fromJSON where map.isKeyPresent: + if let transformedValues = fromJSONArrayWithTransform(map.currentValue, transform: transform) { + FromJSON.basicType(&left, object: Set(transformedValues)) + } + case .toJSON: + left >>> right + default: () + } +} + +public func >>> (left: Set?, right: (Map, Transform)) where Transform.Object: BaseMappable { + let (map, transform) = right + if map.mappingType == .toJSON { + if let values = left { + let transformedValues = toJSONArrayWithTransform(Array(values), transform: transform) + ToJSON.optionalBasicType(transformedValues, map: map) + } + } +} + + +/// 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 + switch map.mappingType { + case .fromJSON where map.isKeyPresent: + if let transformedValues = fromJSONArrayWithTransform(map.currentValue, transform: transform) { + FromJSON.basicType(&left, object: Set(transformedValues)) + } + case .toJSON: + left >>> right + default: () + } +} + + +private func fromJSONArrayWithTransform(_ input: Any?, transform: Transform) -> [Transform.Object]? { + if let values = input as? [Any] { + return values.flatMap { value in + return transform.transformFromJSON(value) + } + } else { + return nil + } +} + +private func fromJSONDictionaryWithTransform(_ input: Any?, transform: Transform) -> [String: Transform.Object]? { + if let values = input as? [String: Any] { + return values.filterMap { value in + return transform.transformFromJSON(value) + } + } else { + return nil + } +} + +private func toJSONArrayWithTransform(_ input: [Transform.Object]?, transform: Transform) -> [Transform.JSON]? { + return input?.flatMap { value in + return transform.transformToJSON(value) + } +} + +private func toJSONDictionaryWithTransform(_ input: [String: Transform.Object]?, transform: Transform) -> [String: Transform.JSON]? { + return input?.filterMap { value in + return transform.transformToJSON(value) + } +} diff --git a/Example/Pods/ObjectMapper/ObjectMapper/Transforms/TransformType.swift b/Example/Pods/ObjectMapper/Sources/TransformType.swift similarity index 97% rename from Example/Pods/ObjectMapper/ObjectMapper/Transforms/TransformType.swift rename to Example/Pods/ObjectMapper/Sources/TransformType.swift index 8916694..61578c3 100644 --- a/Example/Pods/ObjectMapper/ObjectMapper/Transforms/TransformType.swift +++ b/Example/Pods/ObjectMapper/Sources/TransformType.swift @@ -6,7 +6,7 @@ // // The MIT License (MIT) // -// Copyright (c) 2014-2015 Hearst +// Copyright (c) 2014-2016 Hearst // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Example/Pods/ObjectMapper/ObjectMapper/Transforms/URLTransform.swift b/Example/Pods/ObjectMapper/Sources/URLTransform.swift similarity index 83% rename from Example/Pods/ObjectMapper/ObjectMapper/Transforms/URLTransform.swift rename to Example/Pods/ObjectMapper/Sources/URLTransform.swift index ee2c1ac..5624476 100644 --- a/Example/Pods/ObjectMapper/ObjectMapper/Transforms/URLTransform.swift +++ b/Example/Pods/ObjectMapper/Sources/URLTransform.swift @@ -6,7 +6,7 @@ // // The MIT License (MIT) // -// Copyright (c) 2014-2015 Hearst +// Copyright (c) 2014-2016 Hearst // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -32,6 +32,7 @@ open class URLTransform: TransformType { public typealias Object = URL public typealias JSON = String private let shouldEncodeURLString: Bool + private let allowedCharacterSet: CharacterSet /** Initializes the URLTransform with an option to encode URL strings before converting them to an NSURL @@ -39,24 +40,25 @@ open class URLTransform: TransformType { to `NSURL(string:)` - returns: an initialized transformer */ - public init(shouldEncodeURLString: Bool = true) { + public init(shouldEncodeURLString: Bool = false, allowedCharacterSet: CharacterSet = .urlQueryAllowed) { self.shouldEncodeURLString = shouldEncodeURLString + self.allowedCharacterSet = allowedCharacterSet } - public func transformFromJSON(_ value: Any?) -> URL? { + open func transformFromJSON(_ value: Any?) -> URL? { guard let URLString = value as? String else { return nil } if !shouldEncodeURLString { return URL(string: URLString) } - - guard let escapedURLString = URLString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) else { + + guard let escapedURLString = URLString.addingPercentEncoding(withAllowedCharacters: allowedCharacterSet) else { return nil } return URL(string: escapedURLString) } - public func transformToJSON(_ value: URL?) -> String? { + open func transformToJSON(_ value: URL?) -> String? { if let URL = value { return URL.absoluteString } diff --git a/Example/Pods/Pods.xcodeproj/project.pbxproj b/Example/Pods/Pods.xcodeproj/project.pbxproj index 535f231..f727117 100644 --- a/Example/Pods/Pods.xcodeproj/project.pbxproj +++ b/Example/Pods/Pods.xcodeproj/project.pbxproj @@ -7,39 +7,45 @@ objects = { /* Begin PBXBuildFile section */ + 086A8AF4D45C37DBF66FFE06E0E53EAB /* FromJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5BF0B134157103FEB6F696A98717239 /* FromJSON.swift */; }; + 0A14CF82F625AADBB9B9C6EE2A7993AA /* IntegerOperators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FA3A66A9DB9005FD97A879F6E83548C /* IntegerOperators.swift */; }; + 0B007CC659F8554C442D7EF9C377078A /* MapError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9ED836E99AE21969C18AFBBA73D80A94 /* MapError.swift */; }; 0BB4EF281398F2725F72FDEE1810B637 /* Pods-APNSUtil_Example-umbrella.h in Headers */ = {isa = PBXBuildFile; fileRef = 7397B3445CE676557E4265AC8EF876BD /* Pods-APNSUtil_Example-umbrella.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 145F6799296F51B9F7873400A3D8A139 /* TransformOf.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12D80EDCBFDADFEAF83E73B1F4298320 /* TransformOf.swift */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; 19A895C2151A5A4B52BCD5D5E9797B6F /* APNSManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 587052262552155C7131469CDD7F8A52 /* APNSManager.swift */; }; - 1F2E918A8908D3D92E4182C36753837C /* Operators.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF0D03B56D4F7FCD2115F600E9B3EBEB /* Operators.swift */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; + 21B8AED5D25F4B2C7255A9C3A9DE9009 /* Map.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6120B0816E36E534E503459F567D5F2E /* Map.swift */; }; + 2DBA6D39E5E5D7B47DF44F6050FEE260 /* ObjectMapper-dummy.m in Sources */ = {isa = PBXBuildFile; fileRef = 3257FCB53D1328D3334C0D3C5065FBBF /* ObjectMapper-dummy.m */; }; 44293254A39E424D2CB406C290761A8B /* APNSInstance.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7029C9DB50DDA75466AA7966D21DD26 /* APNSInstance.swift */; }; - 474BC828D1115EB6A350756458E0CD06 /* ObjectMapper-umbrella.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E3C40B9A5500F757AE2B4B683445695 /* ObjectMapper-umbrella.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 482C235C5F03C7EEB6AC3B12245A3BBC /* Map.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E8359AB8D753A60C5C56B0034310570 /* Map.swift */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - 5BDAA3E3F32E24BBB3A49A154BD2F566 /* ObjectMapper-dummy.m in Sources */ = {isa = PBXBuildFile; fileRef = 93F8B9088984CF79F217D0181BD4E544 /* ObjectMapper-dummy.m */; }; - 5C8ADD24DF4288FFD90DB7647C1C3D62 /* Mapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 112D75C7A5A386F5ABAEF337FB8F57EC /* Mapper.swift */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - 69B06A09B453136BF0DA5CF0F254F2E7 /* FromJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61998C6866565296C0486EBA1527EA1A /* FromJSON.swift */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - 8C33A9D0E248A6EA1A49B689CADFAA7E /* DataTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = E76DA17569AC50A6854CE5717667831D /* DataTransform.swift */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - 93D135DD91E720E4B0E418749FD06299 /* TransformType.swift in Sources */ = {isa = PBXBuildFile; fileRef = A06BAACE3FA7D3CBE72A76C4BA017E48 /* TransformType.swift */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - 946855648446BD41EEB975BCC6E617D0 /* Mappable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AB688F03D047D5077D38B60DD99FBAE /* Mappable.swift */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; + 474BC828D1115EB6A350756458E0CD06 /* ObjectMapper-umbrella.h in Headers */ = {isa = PBXBuildFile; fileRef = 516E764F46138FFBA9179E7EE76DB943 /* ObjectMapper-umbrella.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 52352D8AE4204254CF01F4C61E2DBACA /* ImmutableMappable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 767F089886989F6B9C79D75736C0BB57 /* ImmutableMappable.swift */; }; + 6642343C39E61A97888633E5D3616551 /* Mapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB0E4295B6584D52405249434A611730 /* Mapper.swift */; }; + 669D8F671D23CE98407225F0D17CF5C9 /* TransformOperators.swift in Sources */ = {isa = PBXBuildFile; fileRef = A99342F019C81C5AE15B9FD7009B4E52 /* TransformOperators.swift */; }; + 66C7E88A92C4A4FC90E950F03EA3F3B3 /* CustomDateFormatTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = E83936D4B9772BB61E1C33AA865075BA /* CustomDateFormatTransform.swift */; }; + 6AB999682AEADEC01033A502E5D4DF66 /* EnumTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA8903DF0A4E2F85EE8118C3A85A8449 /* EnumTransform.swift */; }; + 7D43908E837AEA87F9EC7AB9CA7D5F05 /* NSDecimalNumberTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03735EF0E77C1DDACDF7C9A83303C091 /* NSDecimalNumberTransform.swift */; }; + 80A5224ACFBEE451D8E2BB597D51B04C /* HexColorTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9619F2DCB9545FF6416CC1520E8A289 /* HexColorTransform.swift */; }; 95BF1622195CDF8B8F272F3A09C27B48 /* ObjectMapper.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 515BB24BCB558A6C6816DC6C1C97492C /* ObjectMapper.framework */; }; - 9B5A0B1F3D35B736FBD6DE2D7AEE1AB5 /* ToJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 027C6B65C90B5085666C806F6A5AB721 /* ToJSON.swift */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; 9BE8BFDAFD5FFF6562683DF6A3E075AC /* Pods-APNSUtil_Tests-dummy.m in Sources */ = {isa = PBXBuildFile; fileRef = 6CB105BC1AD4C3A47657CB05A517C95C /* Pods-APNSUtil_Tests-dummy.m */; }; - A4ABDF7DA8DEFD6C5F902A37F57ACCC6 /* URLTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8DE9E0EBFB8EC6494211B4FC150DA5B2 /* URLTransform.swift */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; + A0211B66CDF5096C93213096CAB483DA /* EnumOperators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51737AB9AC204BFA21929556B7D8A784 /* EnumOperators.swift */; }; A86EC6FA9849E85E07CDAA83213CC8FD /* Pods-APNSUtil_Tests-umbrella.h in Headers */ = {isa = PBXBuildFile; fileRef = 8CAA54154B306944E1171E39A9C6DBA9 /* Pods-APNSUtil_Tests-umbrella.h */; settings = {ATTRIBUTES = (Public, ); }; }; - AE9A572F49619A67EA839319EC4D3B52 /* NSDecimalNumberTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C835719301CE6AD3F310BE0A775E3 /* NSDecimalNumberTransform.swift */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; + AE5FA5CC909C66AC780471FC2436687B /* DictionaryTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1AB1F917FD0794BF93B05D9A01C52FB /* DictionaryTransform.swift */; }; B06D659923AA2EB173C0C7C442F63EBE /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BBF2A8127EDF29ABAA8C2FD230237309 /* Foundation.framework */; }; - B2460C7DE53E260EEB686A681FA3B50C /* CustomDateFormatTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE4D02DC965DE9E40147BD31446858DF /* CustomDateFormatTransform.swift */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - BC8A6A56332550BA8971E030F3D7D8AF /* DictionaryTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = C37D9B1E53E879BF167168969D1EEAB6 /* DictionaryTransform.swift */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; + B3B81E463BC81C00610AF41B78AEC7D6 /* DataTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = D008BDF2149DE2E101DD576A6D9FCDFB /* DataTransform.swift */; }; BDCD0842F48C5A23486CD1B0E4376D0B /* APNSUtil-dummy.m in Sources */ = {isa = PBXBuildFile; fileRef = D85D4A4452EDE5AA1605B4E8E5F8A09C /* APNSUtil-dummy.m */; }; + C16DC31933B961B45FC44C858C620D57 /* Operators.swift in Sources */ = {isa = PBXBuildFile; fileRef = F67846576657F67A40688F35D8BBF4F5 /* Operators.swift */; }; C1A7AC15996C3A3B90B73914563CEEB9 /* NSObject+Codable.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEC3C2FE1CC510FE756FF9F09D6D0C2D /* NSObject+Codable.swift */; }; + C838DE7EDB4FDC47FCD3018DB34443AF /* ToJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = F825ABC70E24EFAF9D9357AE3EF270C5 /* ToJSON.swift */; }; CA685C6CACDDCAD80706FE33EF9A1905 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BBF2A8127EDF29ABAA8C2FD230237309 /* Foundation.framework */; }; CAC46E189303160EBAB515A335C99D37 /* APNSUtil-umbrella.h in Headers */ = {isa = PBXBuildFile; fileRef = 9C4B45C0912C00EA24AB9369BAE3339F /* APNSUtil-umbrella.h */; settings = {ATTRIBUTES = (Public, ); }; }; - D21EDFD6C67B02EDF959000665672155 /* EnumTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB4229A951C4A418977079EBDF91F868 /* EnumTransform.swift */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; + CCB5E192A3648BAC01F775D8FEF8367B /* Mappable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29707823C343DB3178B8BD2738202502 /* Mappable.swift */; }; + D032EE0329B34654DE7C65A43474A7AD /* DateFormatterTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B05DBA920727DA97A2230EC1D55998F /* DateFormatterTransform.swift */; }; D7321A0F3650CDAC522A1CB5D94B2ACD /* Pods-APNSUtil_Example-dummy.m in Sources */ = {isa = PBXBuildFile; fileRef = 1CD771035EC108995DC9E7BF9872C60A /* Pods-APNSUtil_Example-dummy.m */; }; D7414CF8CFD499D328E07EE53D88BA7F /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BBF2A8127EDF29ABAA8C2FD230237309 /* Foundation.framework */; }; - DED06D4BE1E80D6EFE672D8C9432C17F /* ISO8601DateTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B44FDBB52336DEED4EE3B4E24A7E0E9 /* ISO8601DateTransform.swift */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; + DCAB3433A670BDF58C354F20B1670434 /* TransformType.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA25BC5EA0ED4E982FF381F264738E55 /* TransformType.swift */; }; + DD28908AC1D5C478DC67ECA80BF0074A /* ISO8601DateTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049BA216F194C705BC41B6247C3D93F8 /* ISO8601DateTransform.swift */; }; E910392E480DF8A592D7008A1EA61A83 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BBF2A8127EDF29ABAA8C2FD230237309 /* Foundation.framework */; }; - FDCE519E6BD4BBCF2B77C916CC03D39A /* DateFormatterTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D876A505779BD7A784A15AFF71738D /* DateFormatterTransform.swift */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - FE8228473A48EAEEA8BCAC34BD19AA5C /* DateTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F2E86CC5E4EDCF1ACB7B71EECAE2B97 /* DateTransform.swift */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; + F19BA340DCAEFE6014E919C73A3624FC /* TransformOf.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B464D60284C4B2CA3692CEE336D072A /* TransformOf.swift */; }; + F27EC6987FD85560B14A2947B1717EF7 /* DateTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = 798746DC36878BAB77E1AEB5ACD85688 /* DateTransform.swift */; }; + F6E786841CF58C38A04BFEF25487FC9C /* URLTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1FE2520AB1362BD0248CA322C2139490 /* URLTransform.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -67,65 +73,71 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 027C6B65C90B5085666C806F6A5AB721 /* ToJSON.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = ToJSON.swift; path = ObjectMapper/Core/ToJSON.swift; sourceTree = ""; }; + 03735EF0E77C1DDACDF7C9A83303C091 /* NSDecimalNumberTransform.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = NSDecimalNumberTransform.swift; path = Sources/NSDecimalNumberTransform.swift; sourceTree = ""; }; + 049BA216F194C705BC41B6247C3D93F8 /* ISO8601DateTransform.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = ISO8601DateTransform.swift; path = Sources/ISO8601DateTransform.swift; sourceTree = ""; }; 09AE27EA9A97A5B89E53D965E992C566 /* APNSUtil.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = APNSUtil.xcconfig; sourceTree = ""; }; - 09D876A505779BD7A784A15AFF71738D /* DateFormatterTransform.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = DateFormatterTransform.swift; path = ObjectMapper/Transforms/DateFormatterTransform.swift; sourceTree = ""; }; + 0A154416713C3455D93004912682A00F /* ObjectMapper.modulemap */ = {isa = PBXFileReference; includeInIndex = 1; path = ObjectMapper.modulemap; sourceTree = ""; }; 0D17CC6CD5634D88F677162DE709787C /* Pods-APNSUtil_Example-acknowledgements.markdown */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; path = "Pods-APNSUtil_Example-acknowledgements.markdown"; sourceTree = ""; }; - 112D75C7A5A386F5ABAEF337FB8F57EC /* Mapper.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = Mapper.swift; path = ObjectMapper/Core/Mapper.swift; sourceTree = ""; }; - 12D80EDCBFDADFEAF83E73B1F4298320 /* TransformOf.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = TransformOf.swift; path = ObjectMapper/Transforms/TransformOf.swift; sourceTree = ""; }; + 1B464D60284C4B2CA3692CEE336D072A /* TransformOf.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = TransformOf.swift; path = Sources/TransformOf.swift; sourceTree = ""; }; 1CD771035EC108995DC9E7BF9872C60A /* Pods-APNSUtil_Example-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "Pods-APNSUtil_Example-dummy.m"; sourceTree = ""; }; - 21249291725D837BF8985189444FFEBA /* ObjectMapper.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = ObjectMapper.xcconfig; sourceTree = ""; }; + 1FE2520AB1362BD0248CA322C2139490 /* URLTransform.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = URLTransform.swift; path = Sources/URLTransform.swift; sourceTree = ""; }; 27F0F76988C7FCBF2C7ADD2BE7268A84 /* Pods-APNSUtil_Example-frameworks.sh */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.script.sh; path = "Pods-APNSUtil_Example-frameworks.sh"; sourceTree = ""; }; + 29707823C343DB3178B8BD2738202502 /* Mappable.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = Mappable.swift; path = Sources/Mappable.swift; sourceTree = ""; }; 320FD2F8732D20C07C0185EEA77D913F /* Pods-APNSUtil_Tests-frameworks.sh */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.script.sh; path = "Pods-APNSUtil_Tests-frameworks.sh"; sourceTree = ""; }; + 3257FCB53D1328D3334C0D3C5065FBBF /* ObjectMapper-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "ObjectMapper-dummy.m"; sourceTree = ""; }; 392D62C79253E56D8D4FC9B77BCEBEC7 /* Pods-APNSUtil_Example.modulemap */ = {isa = PBXFileReference; includeInIndex = 1; path = "Pods-APNSUtil_Example.modulemap"; sourceTree = ""; }; 3971FD2397168A24DC2BE8DC1CF11C06 /* Pods-APNSUtil_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-APNSUtil_Tests.release.xcconfig"; sourceTree = ""; }; - 3A5281418FEC9184304F69218872F5CA /* ObjectMapper-prefix.pch */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "ObjectMapper-prefix.pch"; sourceTree = ""; }; - 3AB688F03D047D5077D38B60DD99FBAE /* Mappable.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = Mappable.swift; path = ObjectMapper/Core/Mappable.swift; sourceTree = ""; }; 3DED118962D9F865289E1CE69E407B65 /* APNSUtil-prefix.pch */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "APNSUtil-prefix.pch"; sourceTree = ""; }; - 3E3C40B9A5500F757AE2B4B683445695 /* ObjectMapper-umbrella.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "ObjectMapper-umbrella.h"; sourceTree = ""; }; 4CB4A28D3BE28D53BF26FFAA7E02BDCE /* Pods-APNSUtil_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-APNSUtil_Example.debug.xcconfig"; sourceTree = ""; }; + 4FA3A66A9DB9005FD97A879F6E83548C /* IntegerOperators.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = IntegerOperators.swift; path = Sources/IntegerOperators.swift; sourceTree = ""; }; 515BB24BCB558A6C6816DC6C1C97492C /* ObjectMapper.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ObjectMapper.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 516E764F46138FFBA9179E7EE76DB943 /* ObjectMapper-umbrella.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "ObjectMapper-umbrella.h"; sourceTree = ""; }; + 51737AB9AC204BFA21929556B7D8A784 /* EnumOperators.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = EnumOperators.swift; path = Sources/EnumOperators.swift; sourceTree = ""; }; 56E140897C7688E1E4A1BA84BFBA0658 /* ObjectMapper.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; name = ObjectMapper.framework; path = ObjectMapper.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 587052262552155C7131469CDD7F8A52 /* APNSManager.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = APNSManager.swift; path = APNSUtil/Classes/APNSManager.swift; sourceTree = ""; }; 59373EB39F10851BE99AC26F256DB1E8 /* Pods-APNSUtil_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-APNSUtil_Tests.debug.xcconfig"; sourceTree = ""; }; - 5B44FDBB52336DEED4EE3B4E24A7E0E9 /* ISO8601DateTransform.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = ISO8601DateTransform.swift; path = ObjectMapper/Transforms/ISO8601DateTransform.swift; sourceTree = ""; }; - 5F2E86CC5E4EDCF1ACB7B71EECAE2B97 /* DateTransform.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = DateTransform.swift; path = ObjectMapper/Transforms/DateTransform.swift; sourceTree = ""; }; - 61998C6866565296C0486EBA1527EA1A /* FromJSON.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = FromJSON.swift; path = ObjectMapper/Core/FromJSON.swift; sourceTree = ""; }; - 656C835719301CE6AD3F310BE0A775E3 /* NSDecimalNumberTransform.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = NSDecimalNumberTransform.swift; path = ObjectMapper/Transforms/NSDecimalNumberTransform.swift; sourceTree = ""; }; + 6120B0816E36E534E503459F567D5F2E /* Map.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = Map.swift; path = Sources/Map.swift; sourceTree = ""; }; 6CB105BC1AD4C3A47657CB05A517C95C /* Pods-APNSUtil_Tests-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "Pods-APNSUtil_Tests-dummy.m"; sourceTree = ""; }; 725C6A197DCDE3F393B6572AC55AFC02 /* Pods_APNSUtil_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; name = Pods_APNSUtil_Example.framework; path = "Pods-APNSUtil_Example.framework"; sourceTree = BUILT_PRODUCTS_DIR; }; + 7293376908DF07F84864AFD1508C0E8E /* Info.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 7397B3445CE676557E4265AC8EF876BD /* Pods-APNSUtil_Example-umbrella.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "Pods-APNSUtil_Example-umbrella.h"; sourceTree = ""; }; + 767F089886989F6B9C79D75736C0BB57 /* ImmutableMappable.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = ImmutableMappable.swift; path = Sources/ImmutableMappable.swift; sourceTree = ""; }; + 798746DC36878BAB77E1AEB5ACD85688 /* DateTransform.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = DateTransform.swift; path = Sources/DateTransform.swift; sourceTree = ""; }; 8767D444FE177C59E23970E08CF68225 /* Pods-APNSUtil_Example-acknowledgements.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-APNSUtil_Example-acknowledgements.plist"; sourceTree = ""; }; + 8B05DBA920727DA97A2230EC1D55998F /* DateFormatterTransform.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = DateFormatterTransform.swift; path = Sources/DateFormatterTransform.swift; sourceTree = ""; }; 8CAA54154B306944E1171E39A9C6DBA9 /* Pods-APNSUtil_Tests-umbrella.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "Pods-APNSUtil_Tests-umbrella.h"; sourceTree = ""; }; - 8DE9E0EBFB8EC6494211B4FC150DA5B2 /* URLTransform.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = URLTransform.swift; path = ObjectMapper/Transforms/URLTransform.swift; sourceTree = ""; }; - 8E8359AB8D753A60C5C56B0034310570 /* Map.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = Map.swift; path = ObjectMapper/Core/Map.swift; sourceTree = ""; }; 92CAA0BD4FF82C53F443C5226F9305AA /* APNSUtil.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; name = APNSUtil.framework; path = APNSUtil.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 93A4A3777CF96A4AAC1D13BA6DCCEA73 /* Podfile */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; lastKnownFileType = text; name = Podfile; path = ../Podfile; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; - 93F8B9088984CF79F217D0181BD4E544 /* ObjectMapper-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "ObjectMapper-dummy.m"; sourceTree = ""; }; 9C4B45C0912C00EA24AB9369BAE3339F /* APNSUtil-umbrella.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "APNSUtil-umbrella.h"; sourceTree = ""; }; 9C79093F5C906DC4CB16D970C5816825 /* Pods-APNSUtil_Tests-acknowledgements.markdown */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; path = "Pods-APNSUtil_Tests-acknowledgements.markdown"; sourceTree = ""; }; - A06BAACE3FA7D3CBE72A76C4BA017E48 /* TransformType.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = TransformType.swift; path = ObjectMapper/Transforms/TransformType.swift; sourceTree = ""; }; + 9ED836E99AE21969C18AFBBA73D80A94 /* MapError.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = MapError.swift; path = Sources/MapError.swift; sourceTree = ""; }; A51A6C3FF908D263D09B7AE96F97FE4B /* APNSUtil.modulemap */ = {isa = PBXFileReference; includeInIndex = 1; path = APNSUtil.modulemap; sourceTree = ""; }; + A99342F019C81C5AE15B9FD7009B4E52 /* TransformOperators.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = TransformOperators.swift; path = Sources/TransformOperators.swift; sourceTree = ""; }; AE3D4EDB6EB4071B87FF7098578B552C /* Info.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; AEC3C2FE1CC510FE756FF9F09D6D0C2D /* NSObject+Codable.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = "NSObject+Codable.swift"; path = "APNSUtil/Classes/NSObject+Codable.swift"; sourceTree = ""; }; + B9619F2DCB9545FF6416CC1520E8A289 /* HexColorTransform.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = HexColorTransform.swift; path = Sources/HexColorTransform.swift; sourceTree = ""; }; BBF2A8127EDF29ABAA8C2FD230237309 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.3.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; }; BCB4B5C28ABD64CF463BB5295406D0BD /* Pods-APNSUtil_Tests-acknowledgements.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-APNSUtil_Tests-acknowledgements.plist"; sourceTree = ""; }; - BE4D02DC965DE9E40147BD31446858DF /* CustomDateFormatTransform.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = CustomDateFormatTransform.swift; path = ObjectMapper/Transforms/CustomDateFormatTransform.swift; sourceTree = ""; }; - C37D9B1E53E879BF167168969D1EEAB6 /* DictionaryTransform.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = DictionaryTransform.swift; path = ObjectMapper/Transforms/DictionaryTransform.swift; sourceTree = ""; }; + BF1266B3B4CD82D5A49B6946BF2E5AE8 /* ObjectMapper.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = ObjectMapper.xcconfig; sourceTree = ""; }; + C43F52FA658A88DCEB2B063351BC3F4F /* ObjectMapper-prefix.pch */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "ObjectMapper-prefix.pch"; sourceTree = ""; }; C59F825AB4E361ABE6BBAD7933FF5C8F /* Pods-APNSUtil_Tests-resources.sh */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.script.sh; path = "Pods-APNSUtil_Tests-resources.sh"; sourceTree = ""; }; + CA25BC5EA0ED4E982FF381F264738E55 /* TransformType.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = TransformType.swift; path = Sources/TransformType.swift; sourceTree = ""; }; CD774CC9E8D702A259B90D2E907EEDFB /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; path = LICENSE; sourceTree = ""; }; - D7AC23C67BBBDA6981B12C6DE90F51BC /* ObjectMapper.modulemap */ = {isa = PBXFileReference; includeInIndex = 1; path = ObjectMapper.modulemap; sourceTree = ""; }; + D008BDF2149DE2E101DD576A6D9FCDFB /* DataTransform.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = DataTransform.swift; path = Sources/DataTransform.swift; sourceTree = ""; }; + D5BF0B134157103FEB6F696A98717239 /* FromJSON.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = FromJSON.swift; path = Sources/FromJSON.swift; sourceTree = ""; }; D85D4A4452EDE5AA1605B4E8E5F8A09C /* APNSUtil-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "APNSUtil-dummy.m"; sourceTree = ""; }; - DB4229A951C4A418977079EBDF91F868 /* EnumTransform.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = EnumTransform.swift; path = ObjectMapper/Transforms/EnumTransform.swift; sourceTree = ""; }; - DCD72DD56EA5A48818EA6E52DF8C3094 /* Info.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + DA8903DF0A4E2F85EE8118C3A85A8449 /* EnumTransform.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = EnumTransform.swift; path = Sources/EnumTransform.swift; sourceTree = ""; }; E040EFB9B0D05472D9D859586664F0B9 /* Info.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; E218CD0160F90E89470DAF4345708DE9 /* Pods_APNSUtil_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; name = Pods_APNSUtil_Tests.framework; path = "Pods-APNSUtil_Tests.framework"; sourceTree = BUILT_PRODUCTS_DIR; }; - E76DA17569AC50A6854CE5717667831D /* DataTransform.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = DataTransform.swift; path = ObjectMapper/Transforms/DataTransform.swift; sourceTree = ""; }; - EF0D03B56D4F7FCD2115F600E9B3EBEB /* Operators.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = Operators.swift; path = ObjectMapper/Core/Operators.swift; sourceTree = ""; }; + E83936D4B9772BB61E1C33AA865075BA /* CustomDateFormatTransform.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = CustomDateFormatTransform.swift; path = Sources/CustomDateFormatTransform.swift; sourceTree = ""; }; F11AED055135CDAAF38E6A682B6F7C79 /* Pods-APNSUtil_Tests.modulemap */ = {isa = PBXFileReference; includeInIndex = 1; path = "Pods-APNSUtil_Tests.modulemap"; sourceTree = ""; }; + F1AB1F917FD0794BF93B05D9A01C52FB /* DictionaryTransform.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = DictionaryTransform.swift; path = Sources/DictionaryTransform.swift; sourceTree = ""; }; F418F53A54152E9BF9557E1ACFB5B443 /* APNSUtil.podspec */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; lastKnownFileType = text; path = APNSUtil.podspec; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; + F67846576657F67A40688F35D8BBF4F5 /* Operators.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = Operators.swift; path = Sources/Operators.swift; sourceTree = ""; }; F7029C9DB50DDA75466AA7966D21DD26 /* APNSInstance.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = APNSInstance.swift; path = APNSUtil/Classes/APNSInstance.swift; sourceTree = ""; }; + F825ABC70E24EFAF9D9357AE3EF270C5 /* ToJSON.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = ToJSON.swift; path = Sources/ToJSON.swift; sourceTree = ""; }; F92F50CB3C736800443092405446401B /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; path = README.md; sourceTree = ""; }; + FB0E4295B6584D52405249434A611730 /* Mapper.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = Mapper.swift; path = Sources/Mapper.swift; sourceTree = ""; }; FC307F4C23F997DA113D80015F941DBD /* Pods-APNSUtil_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-APNSUtil_Example.release.xcconfig"; sourceTree = ""; }; FCD9E18BC979789AB8186E09BC95A7B3 /* Pods-APNSUtil_Example-resources.sh */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.script.sh; path = "Pods-APNSUtil_Example-resources.sh"; sourceTree = ""; }; FE2FF7AA3A0E537BC4C4161824C84CCD /* Info.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -210,38 +222,26 @@ name = Pod; sourceTree = ""; }; - 4E103E339AE2E1444F45080D1F1AB2E0 /* Development Pods */ = { + 44B8248DC68B6AABFCF1F66C140130D0 /* Support Files */ = { isa = PBXGroup; children = ( - A2012C444B5A9CC33B9CE55D8A37288A /* APNSUtil */, + 7293376908DF07F84864AFD1508C0E8E /* Info.plist */, + 0A154416713C3455D93004912682A00F /* ObjectMapper.modulemap */, + BF1266B3B4CD82D5A49B6946BF2E5AE8 /* ObjectMapper.xcconfig */, + 3257FCB53D1328D3334C0D3C5065FBBF /* ObjectMapper-dummy.m */, + C43F52FA658A88DCEB2B063351BC3F4F /* ObjectMapper-prefix.pch */, + 516E764F46138FFBA9179E7EE76DB943 /* ObjectMapper-umbrella.h */, ); - name = "Development Pods"; + name = "Support Files"; + path = "../Target Support Files/ObjectMapper"; sourceTree = ""; }; - 50DA52F9ED8316228A443D4AEB77D3E7 /* ObjectMapper */ = { + 4E103E339AE2E1444F45080D1F1AB2E0 /* Development Pods */ = { isa = PBXGroup; children = ( - BE4D02DC965DE9E40147BD31446858DF /* CustomDateFormatTransform.swift */, - E76DA17569AC50A6854CE5717667831D /* DataTransform.swift */, - 09D876A505779BD7A784A15AFF71738D /* DateFormatterTransform.swift */, - 5F2E86CC5E4EDCF1ACB7B71EECAE2B97 /* DateTransform.swift */, - C37D9B1E53E879BF167168969D1EEAB6 /* DictionaryTransform.swift */, - DB4229A951C4A418977079EBDF91F868 /* EnumTransform.swift */, - 61998C6866565296C0486EBA1527EA1A /* FromJSON.swift */, - 5B44FDBB52336DEED4EE3B4E24A7E0E9 /* ISO8601DateTransform.swift */, - 8E8359AB8D753A60C5C56B0034310570 /* Map.swift */, - 3AB688F03D047D5077D38B60DD99FBAE /* Mappable.swift */, - 112D75C7A5A386F5ABAEF337FB8F57EC /* Mapper.swift */, - 656C835719301CE6AD3F310BE0A775E3 /* NSDecimalNumberTransform.swift */, - EF0D03B56D4F7FCD2115F600E9B3EBEB /* Operators.swift */, - 027C6B65C90B5085666C806F6A5AB721 /* ToJSON.swift */, - 12D80EDCBFDADFEAF83E73B1F4298320 /* TransformOf.swift */, - A06BAACE3FA7D3CBE72A76C4BA017E48 /* TransformType.swift */, - 8DE9E0EBFB8EC6494211B4FC150DA5B2 /* URLTransform.swift */, - F5D91224DF0AE46871245DA803B28C87 /* Support Files */, + A2012C444B5A9CC33B9CE55D8A37288A /* APNSUtil */, ); - name = ObjectMapper; - path = ObjectMapper; + name = "Development Pods"; sourceTree = ""; }; 72A4F101D4D40D3C9EBA12D90663F5FA /* Frameworks */ = { @@ -268,20 +268,12 @@ 93A4A3777CF96A4AAC1D13BA6DCCEA73 /* Podfile */, 4E103E339AE2E1444F45080D1F1AB2E0 /* Development Pods */, 72A4F101D4D40D3C9EBA12D90663F5FA /* Frameworks */, - 96AD02A43B8F57AD204B714B82B37037 /* Pods */, + CC5B8196EA553435A0AFBC67D217E66A /* Pods */, CCCDE2FA6E8947C9F141F9F07D1B7903 /* Products */, 77FF15A0C96E2572FA18708AB8AFBBF1 /* Targets Support Files */, ); sourceTree = ""; }; - 96AD02A43B8F57AD204B714B82B37037 /* Pods */ = { - isa = PBXGroup; - children = ( - 50DA52F9ED8316228A443D4AEB77D3E7 /* ObjectMapper */, - ); - name = Pods; - sourceTree = ""; - }; A2012C444B5A9CC33B9CE55D8A37288A /* APNSUtil */ = { isa = PBXGroup; children = ( @@ -303,6 +295,14 @@ name = iOS; sourceTree = ""; }; + CC5B8196EA553435A0AFBC67D217E66A /* Pods */ = { + isa = PBXGroup; + children = ( + FC4A35C54D3E8B5ACCFDC068C994443D /* ObjectMapper */, + ); + name = Pods; + sourceTree = ""; + }; CCCDE2FA6E8947C9F141F9F07D1B7903 /* Products */ = { isa = PBXGroup; children = ( @@ -332,18 +332,36 @@ path = "Target Support Files/Pods-APNSUtil_Tests"; sourceTree = ""; }; - F5D91224DF0AE46871245DA803B28C87 /* Support Files */ = { + FC4A35C54D3E8B5ACCFDC068C994443D /* ObjectMapper */ = { isa = PBXGroup; children = ( - DCD72DD56EA5A48818EA6E52DF8C3094 /* Info.plist */, - D7AC23C67BBBDA6981B12C6DE90F51BC /* ObjectMapper.modulemap */, - 21249291725D837BF8985189444FFEBA /* ObjectMapper.xcconfig */, - 93F8B9088984CF79F217D0181BD4E544 /* ObjectMapper-dummy.m */, - 3A5281418FEC9184304F69218872F5CA /* ObjectMapper-prefix.pch */, - 3E3C40B9A5500F757AE2B4B683445695 /* ObjectMapper-umbrella.h */, + E83936D4B9772BB61E1C33AA865075BA /* CustomDateFormatTransform.swift */, + D008BDF2149DE2E101DD576A6D9FCDFB /* DataTransform.swift */, + 8B05DBA920727DA97A2230EC1D55998F /* DateFormatterTransform.swift */, + 798746DC36878BAB77E1AEB5ACD85688 /* DateTransform.swift */, + F1AB1F917FD0794BF93B05D9A01C52FB /* DictionaryTransform.swift */, + 51737AB9AC204BFA21929556B7D8A784 /* EnumOperators.swift */, + DA8903DF0A4E2F85EE8118C3A85A8449 /* EnumTransform.swift */, + D5BF0B134157103FEB6F696A98717239 /* FromJSON.swift */, + B9619F2DCB9545FF6416CC1520E8A289 /* HexColorTransform.swift */, + 767F089886989F6B9C79D75736C0BB57 /* ImmutableMappable.swift */, + 4FA3A66A9DB9005FD97A879F6E83548C /* IntegerOperators.swift */, + 049BA216F194C705BC41B6247C3D93F8 /* ISO8601DateTransform.swift */, + 6120B0816E36E534E503459F567D5F2E /* Map.swift */, + 9ED836E99AE21969C18AFBBA73D80A94 /* MapError.swift */, + 29707823C343DB3178B8BD2738202502 /* Mappable.swift */, + FB0E4295B6584D52405249434A611730 /* Mapper.swift */, + 03735EF0E77C1DDACDF7C9A83303C091 /* NSDecimalNumberTransform.swift */, + F67846576657F67A40688F35D8BBF4F5 /* Operators.swift */, + F825ABC70E24EFAF9D9357AE3EF270C5 /* ToJSON.swift */, + 1B464D60284C4B2CA3692CEE336D072A /* TransformOf.swift */, + A99342F019C81C5AE15B9FD7009B4E52 /* TransformOperators.swift */, + CA25BC5EA0ED4E982FF381F264738E55 /* TransformType.swift */, + 1FE2520AB1362BD0248CA322C2139490 /* URLTransform.swift */, + 44B8248DC68B6AABFCF1F66C140130D0 /* Support Files */, ); - name = "Support Files"; - path = "../Target Support Files/ObjectMapper"; + name = ObjectMapper; + path = ObjectMapper; sourceTree = ""; }; /* End PBXGroup section */ @@ -406,7 +424,7 @@ isa = PBXNativeTarget; buildConfigurationList = 73BC79ED6F797336AE4EFB58D2283593 /* Build configuration list for PBXNativeTarget "ObjectMapper" */; buildPhases = ( - 1C138796FC72E9D76D330DCB81CE191C /* Sources */, + B05C0EC2B40206471597461D13BEB688 /* Sources */, E7E8A9AEF2259F03268A1E07C95020DD /* Frameworks */, 6A8887174504558B14F8198E27964B44 /* Headers */, ); @@ -485,31 +503,6 @@ /* End PBXProject section */ /* Begin PBXSourcesBuildPhase section */ - 1C138796FC72E9D76D330DCB81CE191C /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - B2460C7DE53E260EEB686A681FA3B50C /* CustomDateFormatTransform.swift in Sources */, - 8C33A9D0E248A6EA1A49B689CADFAA7E /* DataTransform.swift in Sources */, - FDCE519E6BD4BBCF2B77C916CC03D39A /* DateFormatterTransform.swift in Sources */, - FE8228473A48EAEEA8BCAC34BD19AA5C /* DateTransform.swift in Sources */, - BC8A6A56332550BA8971E030F3D7D8AF /* DictionaryTransform.swift in Sources */, - D21EDFD6C67B02EDF959000665672155 /* EnumTransform.swift in Sources */, - 69B06A09B453136BF0DA5CF0F254F2E7 /* FromJSON.swift in Sources */, - DED06D4BE1E80D6EFE672D8C9432C17F /* ISO8601DateTransform.swift in Sources */, - 482C235C5F03C7EEB6AC3B12245A3BBC /* Map.swift in Sources */, - 946855648446BD41EEB975BCC6E617D0 /* Mappable.swift in Sources */, - 5C8ADD24DF4288FFD90DB7647C1C3D62 /* Mapper.swift in Sources */, - AE9A572F49619A67EA839319EC4D3B52 /* NSDecimalNumberTransform.swift in Sources */, - 5BDAA3E3F32E24BBB3A49A154BD2F566 /* ObjectMapper-dummy.m in Sources */, - 1F2E918A8908D3D92E4182C36753837C /* Operators.swift in Sources */, - 9B5A0B1F3D35B736FBD6DE2D7AEE1AB5 /* ToJSON.swift in Sources */, - 145F6799296F51B9F7873400A3D8A139 /* TransformOf.swift in Sources */, - 93D135DD91E720E4B0E418749FD06299 /* TransformType.swift in Sources */, - A4ABDF7DA8DEFD6C5F902A37F57ACCC6 /* URLTransform.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; 3B4D08CB7D444814F0003FCC792E49F4 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -537,6 +530,37 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + B05C0EC2B40206471597461D13BEB688 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 66C7E88A92C4A4FC90E950F03EA3F3B3 /* CustomDateFormatTransform.swift in Sources */, + B3B81E463BC81C00610AF41B78AEC7D6 /* DataTransform.swift in Sources */, + D032EE0329B34654DE7C65A43474A7AD /* DateFormatterTransform.swift in Sources */, + F27EC6987FD85560B14A2947B1717EF7 /* DateTransform.swift in Sources */, + AE5FA5CC909C66AC780471FC2436687B /* DictionaryTransform.swift in Sources */, + A0211B66CDF5096C93213096CAB483DA /* EnumOperators.swift in Sources */, + 6AB999682AEADEC01033A502E5D4DF66 /* EnumTransform.swift in Sources */, + 086A8AF4D45C37DBF66FFE06E0E53EAB /* FromJSON.swift in Sources */, + 80A5224ACFBEE451D8E2BB597D51B04C /* HexColorTransform.swift in Sources */, + 52352D8AE4204254CF01F4C61E2DBACA /* ImmutableMappable.swift in Sources */, + 0A14CF82F625AADBB9B9C6EE2A7993AA /* IntegerOperators.swift in Sources */, + DD28908AC1D5C478DC67ECA80BF0074A /* ISO8601DateTransform.swift in Sources */, + 21B8AED5D25F4B2C7255A9C3A9DE9009 /* Map.swift in Sources */, + 0B007CC659F8554C442D7EF9C377078A /* MapError.swift in Sources */, + CCB5E192A3648BAC01F775D8FEF8367B /* Mappable.swift in Sources */, + 6642343C39E61A97888633E5D3616551 /* Mapper.swift in Sources */, + 7D43908E837AEA87F9EC7AB9CA7D5F05 /* NSDecimalNumberTransform.swift in Sources */, + 2DBA6D39E5E5D7B47DF44F6050FEE260 /* ObjectMapper-dummy.m in Sources */, + C16DC31933B961B45FC44C858C620D57 /* Operators.swift in Sources */, + C838DE7EDB4FDC47FCD3018DB34443AF /* ToJSON.swift in Sources */, + F19BA340DCAEFE6014E919C73A3624FC /* TransformOf.swift in Sources */, + 669D8F671D23CE98407225F0D17CF5C9 /* TransformOperators.swift in Sources */, + DCAB3433A670BDF58C354F20B1670434 /* TransformType.swift in Sources */, + F6E786841CF58C38A04BFEF25487FC9C /* URLTransform.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ @@ -595,9 +619,9 @@ }; name = Release; }; - 24804B90D7775CCE25B22321BFAE266F /* Debug */ = { + 31876C97930CC4DD12FA854BCB0E5639 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 21249291725D837BF8985189444FFEBA /* ObjectMapper.xcconfig */; + baseConfigurationReference = BF1266B3B4CD82D5A49B6946BF2E5AE8 /* ObjectMapper.xcconfig */; buildSettings = { CODE_SIGN_IDENTITY = ""; "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; @@ -619,16 +643,16 @@ SKIP_INSTALL = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) "; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; name = Debug; }; - 24A56D7C972D40FFB907E0F145607D8A /* Release */ = { + 4A0977B6810930A17BEC6DFDF27172B5 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 21249291725D837BF8985189444FFEBA /* ObjectMapper.xcconfig */; + baseConfigurationReference = 09AE27EA9A97A5B89E53D965E992C566 /* APNSUtil.xcconfig */; buildSettings = { CODE_SIGN_IDENTITY = ""; "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; @@ -639,24 +663,23 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - GCC_PREFIX_HEADER = "Target Support Files/ObjectMapper/ObjectMapper-prefix.pch"; - INFOPLIST_FILE = "Target Support Files/ObjectMapper/Info.plist"; + GCC_PREFIX_HEADER = "Target Support Files/APNSUtil/APNSUtil-prefix.pch"; + INFOPLIST_FILE = "Target Support Files/APNSUtil/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MODULEMAP_FILE = "Target Support Files/ObjectMapper/ObjectMapper.modulemap"; - PRODUCT_NAME = ObjectMapper; + MODULEMAP_FILE = "Target Support Files/APNSUtil/APNSUtil.modulemap"; + PRODUCT_NAME = APNSUtil; SDKROOT = iphoneos; SKIP_INSTALL = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) "; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; - VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; - name = Release; + name = Debug; }; 559307B8AB4CCDD474746ED406FEA0BF /* Debug */ = { isa = XCBuildConfiguration; @@ -692,6 +715,38 @@ }; name = Debug; }; + 5FDB9D624B59F4AC72A9CF60AF8DA135 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = BF1266B3B4CD82D5A49B6946BF2E5AE8 /* ObjectMapper.xcconfig */; + buildSettings = { + CODE_SIGN_IDENTITY = ""; + "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; + "CODE_SIGN_IDENTITY[sdk=watchos*]" = ""; + CURRENT_PROJECT_VERSION = 1; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + GCC_PREFIX_HEADER = "Target Support Files/ObjectMapper/ObjectMapper-prefix.pch"; + INFOPLIST_FILE = "Target Support Files/ObjectMapper/Info.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MODULEMAP_FILE = "Target Support Files/ObjectMapper/ObjectMapper.modulemap"; + PRODUCT_NAME = ObjectMapper; + SDKROOT = iphoneos; + SKIP_INSTALL = YES; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) "; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 4.0; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Release; + }; 6F9224530522DD3C735EC96CF142642E /* Release */ = { isa = XCBuildConfiguration; buildSettings = { @@ -747,38 +802,6 @@ }; name = Release; }; - 81718501A2D15D4D8FD99948DDABC235 /* Release */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 09AE27EA9A97A5B89E53D965E992C566 /* APNSUtil.xcconfig */; - buildSettings = { - CODE_SIGN_IDENTITY = ""; - "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; - "CODE_SIGN_IDENTITY[sdk=watchos*]" = ""; - CURRENT_PROJECT_VERSION = 1; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - GCC_PREFIX_HEADER = "Target Support Files/APNSUtil/APNSUtil-prefix.pch"; - INFOPLIST_FILE = "Target Support Files/APNSUtil/Info.plist"; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MODULEMAP_FILE = "Target Support Files/APNSUtil/APNSUtil.modulemap"; - PRODUCT_NAME = APNSUtil; - SDKROOT = iphoneos; - SKIP_INSTALL = YES; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) "; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; - TARGETED_DEVICE_FAMILY = "1,2"; - VALIDATE_PRODUCT = YES; - VERSIONING_SYSTEM = "apple-generic"; - VERSION_INFO_PREFIX = ""; - }; - name = Release; - }; A3C56B9052A7C21616CD03199AA251EF /* Debug */ = { isa = XCBuildConfiguration; baseConfigurationReference = 59373EB39F10851BE99AC26F256DB1E8 /* Pods-APNSUtil_Tests.debug.xcconfig */; @@ -904,7 +927,7 @@ }; name = Debug; }; - CF7CE5E1763CB75A53FA25E866520B1A /* Debug */ = { + C53001F88A8D8F981E4EFD3EC86BDB54 /* Release */ = { isa = XCBuildConfiguration; baseConfigurationReference = 09AE27EA9A97A5B89E53D965E992C566 /* APNSUtil.xcconfig */; buildSettings = { @@ -927,13 +950,14 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) "; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; - name = Debug; + name = Release; }; /* End XCBuildConfiguration section */ @@ -950,8 +974,8 @@ 546EEB2C80213DCACC3ECAC3B2221624 /* Build configuration list for PBXNativeTarget "APNSUtil" */ = { isa = XCConfigurationList; buildConfigurations = ( - CF7CE5E1763CB75A53FA25E866520B1A /* Debug */, - 81718501A2D15D4D8FD99948DDABC235 /* Release */, + 4A0977B6810930A17BEC6DFDF27172B5 /* Debug */, + C53001F88A8D8F981E4EFD3EC86BDB54 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; @@ -959,8 +983,8 @@ 73BC79ED6F797336AE4EFB58D2283593 /* Build configuration list for PBXNativeTarget "ObjectMapper" */ = { isa = XCConfigurationList; buildConfigurations = ( - 24804B90D7775CCE25B22321BFAE266F /* Debug */, - 24A56D7C972D40FFB907E0F145607D8A /* Release */, + 31876C97930CC4DD12FA854BCB0E5639 /* Debug */, + 5FDB9D624B59F4AC72A9CF60AF8DA135 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; diff --git a/Example/Pods/Target Support Files/APNSUtil/Info.plist b/Example/Pods/Target Support Files/APNSUtil/Info.plist index 2243fe6..21a30b4 100644 --- a/Example/Pods/Target Support Files/APNSUtil/Info.plist +++ b/Example/Pods/Target Support Files/APNSUtil/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.0.0 + 1.1.0 CFBundleSignature ???? CFBundleVersion diff --git a/Example/Pods/Target Support Files/ObjectMapper/Info.plist b/Example/Pods/Target Support Files/ObjectMapper/Info.plist index 0a12077..90db36a 100644 --- a/Example/Pods/Target Support Files/ObjectMapper/Info.plist +++ b/Example/Pods/Target Support Files/ObjectMapper/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 2.0.0 + 3.1.0 CFBundleSignature ???? CFBundleVersion diff --git a/Example/Pods/Target Support Files/ObjectMapper/ObjectMapper.xcconfig b/Example/Pods/Target Support Files/ObjectMapper/ObjectMapper.xcconfig index 66d1729..565bced 100644 --- a/Example/Pods/Target Support Files/ObjectMapper/ObjectMapper.xcconfig +++ b/Example/Pods/Target Support Files/ObjectMapper/ObjectMapper.xcconfig @@ -8,3 +8,4 @@ PODS_ROOT = ${SRCROOT} PODS_TARGET_SRCROOT = ${PODS_ROOT}/ObjectMapper PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} SKIP_INSTALL = YES +SWIFT_VERSION = 4.0 diff --git a/README.md b/README.md index 3c2fabd..100c62e 100644 --- a/README.md +++ b/README.md @@ -134,10 +134,10 @@ To integrate APNSUtil into your Xcode project using CocoaPods, specify it in you ```ruby source 'https://github.com/CocoaPods/Specs.git' -platform :ios, '8.0' +platform :ios, '9.0' target '' do - pod 'APNSUtil', '~> 1.0.0' + pod 'APNSUtil', '~> 1.1.0' end ``` @@ -161,14 +161,14 @@ $ brew install carthage To integrate Alamofire into your Xcode project using Carthage, specify it in your `Cartfile`: ```ogdl -github "pisces/APNSUtil" ~> 1.0.0 +github "pisces/APNSUtil" ~> 1.1.0 ``` Run `carthage update` to build the framework and drag the built `APNSUtil.framework` into your Xcode project. ## Requirements -iOS Deployment Target 8.0 higher +iOS Deployment Target 9.0 higher ## Author