diff --git a/Mapper.xcodeproj/project.pbxproj b/Mapper.xcodeproj/project.pbxproj index 4aaa2e5..894cb4b 100644 --- a/Mapper.xcodeproj/project.pbxproj +++ b/Mapper.xcodeproj/project.pbxproj @@ -183,23 +183,24 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0900; - LastUpgradeCheck = 0900; + LastUpgradeCheck = 1150; ORGANIZATIONNAME = Lyft; TargetAttributes = { C20174821BD5509D00E4FE18 = { CreatedOnToolsVersion = 7.0; - LastSwiftMigration = 0900; + LastSwiftMigration = 1150; }; EBBAC36E1F95D0B9004E5286 = { CreatedOnToolsVersion = 9.0; DevelopmentTeam = PQMBS3XAY4; + LastSwiftMigration = 1150; ProvisioningStyle = Automatic; }; }; }; buildConfigurationList = C201747D1BD5509D00E4FE18 /* Build configuration list for PBXProject "Mapper" */; compatibilityVersion = "Xcode 6.3"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, @@ -237,7 +238,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi"; + shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; }; /* End PBXShellScriptBuildPhase section */ @@ -282,6 +283,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = NO; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -290,12 +292,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = 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_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -326,6 +330,7 @@ MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -336,6 +341,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = NO; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -344,12 +350,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = 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_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -372,6 +380,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -383,6 +392,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = C2C036D51C2B180D003FB853 /* UniversalFramework_Framework.xcconfig */; buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; APPLICATION_EXTENSION_API_ONLY = YES; CLANG_ENABLE_MODULES = YES; COMBINE_HIDPI_IMAGES = YES; @@ -398,8 +408,8 @@ PRODUCT_NAME = StreemMapper; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 5.0; TVOS_DEPLOYMENT_TARGET = 9.0; }; name = Debug; @@ -408,6 +418,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = C2C036D51C2B180D003FB853 /* UniversalFramework_Framework.xcconfig */; buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; APPLICATION_EXTENSION_API_ONLY = YES; CLANG_ENABLE_MODULES = YES; COMBINE_HIDPI_IMAGES = YES; @@ -423,8 +434,8 @@ PRODUCT_NAME = StreemMapper; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 5.0; TVOS_DEPLOYMENT_TARGET = 9.0; }; name = Release; @@ -448,7 +459,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -472,7 +483,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/Mapper.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Mapper.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Mapper.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Mapper.xcodeproj/xcshareddata/xcschemes/StreemMapper.xcscheme b/Mapper.xcodeproj/xcshareddata/xcschemes/StreemMapper.xcscheme index 7669044..4c61cf4 100644 --- a/Mapper.xcodeproj/xcshareddata/xcschemes/StreemMapper.xcscheme +++ b/Mapper.xcodeproj/xcshareddata/xcschemes/StreemMapper.xcscheme @@ -1,6 +1,6 @@ + + + + - - - - - - - - CFBundleIdentifier $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion - 7.2.0 + 8.0.0 CFBundleName $(PRODUCT_NAME) CFBundlePackageType diff --git a/Sources/Mappable.swift b/Sources/Mappable.swift index 5816597..af12440 100644 --- a/Sources/Mappable.swift +++ b/Sources/Mappable.swift @@ -35,7 +35,7 @@ public protocol Mappable { */ public extension Mappable{ - public static func from(JSON: Any) -> Self? { + static func from(JSON: Any) -> Self? { if let inputValue = JSON as? [AnyHashable: Any]{ return try? self.init(map: Mapper(JSON: inputValue)) } @@ -54,7 +54,7 @@ public extension Mappable{ */ public extension Array where Element: Mappable{ - public static func from(JSON: Any, rootKey: String? = nil) -> [Element]? { + static func from(JSON: Any, rootKey: String? = nil) -> [Element]? { if let inputArray = JSON as? [[AnyHashable: Any]] { return inputArray.map({ try? Element(map: Mapper(JSON: $0))}).compactMap({$0}) } else if let rootKey = rootKey, let inputDict = JSON as? [AnyHashable: Any] { diff --git a/Sources/Mapper.swift b/Sources/Mapper.swift index a4301b8..b34cefc 100644 --- a/Sources/Mapper.swift +++ b/Sources/Mapper.swift @@ -59,7 +59,7 @@ public struct Mapper { - returns: The value for the given field, if it can be converted to the expected type T otherwise nil */ - public func from(field: String) -> T? { + public func optionalFrom(field: String) -> T? { return try? self.from(field: field) } @@ -198,7 +198,7 @@ public struct Mapper { - returns: The value for the given field, if it can be converted to the expected type T otherwise nil */ - public func from(field: String) -> T? { + public func optionalFrom(field: String) -> T? { return try? self.from(field: field) } @@ -215,7 +215,7 @@ public struct Mapper { - returns: The value for the given field, if it can be converted to the expected type [T] */ - public func from(field: String) -> [T]? { + public func optionalFrom(field: String) -> [T]? { return try? self.from(field: field) } @@ -307,7 +307,7 @@ public struct Mapper { - returns: The value for the given field, if it can be converted to the expected type [T] */ - public func from(field: String) -> [T]? where T == T.ConvertedType { + public func optionalFrom(field: String) -> [T]? where T == T.ConvertedType { return try? self.from(field: field) } @@ -353,7 +353,7 @@ public struct Mapper { nil if anything throws */ - public func from(field: String) -> [U: T]? where U == U.ConvertedType, T == T.ConvertedType { + public func optionalFrom(field: String) -> [U: T]? where U == U.ConvertedType, T == T.ConvertedType { return try? self.from(field: field) } @@ -397,7 +397,7 @@ public struct Mapper { nil if anything throws */ - public func from(field: String) -> [U: T]? where U == U.ConvertedType { + public func optionalFrom(field: String) -> [U: T]? where U == U.ConvertedType { return try? self.from(field: field) } @@ -410,9 +410,9 @@ public struct Mapper { - returns: The first non-nil value to be produced from the array of fields, or nil if none exist */ - public func from(fields: [String]) -> T? where T == T.ConvertedType { + public func optionalFrom(fields: [String]) -> T? where T == T.ConvertedType { for field in fields { - if let value: T = try? self.from(field: field) { + if let value: T = self.from(field: field) { return value } } @@ -445,7 +445,7 @@ public struct Mapper { - returns: The date for the given field, or nil if field is not a string or doesn't match the format */ - public func from(field: String, format: String) -> Date? { + public func optionalFrom(field: String, format: String) -> Date? { return try? self.from(field: field, format: format) } @@ -481,7 +481,7 @@ public struct Mapper { */ public func optionalFrom(field: String, transformation: (Any?) throws -> T?) -> T? { - return (try? transformation(try? self.JSONFrom(field: field))).flatMap { $0 } + return (((try? transformation(try? self.JSONFrom(field: field))) as T??)).flatMap { $0 } } // MARK: - Private diff --git a/Sources/Operators.swift b/Sources/Operators.swift index 2d9fdfb..888f24d 100644 --- a/Sources/Operators.swift +++ b/Sources/Operators.swift @@ -13,7 +13,7 @@ public func |> (map: Mapper, key: String) throws -> T { } public func |> (map: Mapper, key: String) -> T? { - return map.from(field: key) + return map.optionalFrom(field: key) } public func |> (map: Mapper, key: String) throws -> [T] @@ -43,13 +43,13 @@ public func |> (map: Mapper, key: String) throws -> [T] where T } public func |> (map: Mapper, key: String) -> [T]? where T == T.ConvertedType { - return map.from(field: key) + return map.optionalFrom(field: key) } public func |> (map: Mapper, key: String) -> [U: T]? where U == U.ConvertedType, T == T.ConvertedType { - return map.from(field: key) + return map.optionalFrom(field: key) } public func |> (map: Mapper, key: String) throws -> [U: T] @@ -63,7 +63,7 @@ public func |> (map: Mapper, keyFormat: (String, String)) throws -> Date { } public func |> (map: Mapper, keyFormat: (String, String)) -> Date? { - return map.from(field: keyFormat.0, format: keyFormat.1) + return map.optionalFrom(field: keyFormat.0, format: keyFormat.1) } // MARK: - Mappable @@ -73,7 +73,7 @@ public func |> (map: Mapper, key: String) throws -> T { } public func |> (map: Mapper, key: String) -> T? { - return map.from(field: key) + return map.optionalFrom(field: key) } public func |> (map: Mapper, key: String) throws -> [T] { @@ -81,11 +81,11 @@ public func |> (map: Mapper, key: String) throws -> [T] { } public func |> (map: Mapper, key: String) -> [T]? { - return map.from(field: key) + return map.optionalFrom(field: key) } public func |> (map: Mapper, key: String) -> [U: T]? where U == U.ConvertedType{ - return map.from(field: key) + return map.optionalFrom(field: key) } public func |> (map: Mapper, key: String) throws -> [U: T] where U == U.ConvertedType{ diff --git a/Sources/Transform+Dictionary.swift b/Sources/Transform+Dictionary.swift index 4cb71f9..6f59b71 100644 --- a/Sources/Transform+Dictionary.swift +++ b/Sources/Transform+Dictionary.swift @@ -46,7 +46,7 @@ public extension Transform { values T are the objects */ - public static func toDictionary(key getKey: @escaping (T) -> U) -> + static func toDictionary(key getKey: @escaping (T) -> U) -> (_ object: Any?) throws -> [U: T] where T: Mappable, U: Hashable { return { object in diff --git a/StreemMapper.podspec b/StreemMapper.podspec index d2261d7..59c515a 100644 --- a/StreemMapper.podspec +++ b/StreemMapper.podspec @@ -1,15 +1,15 @@ Pod::Spec.new do |s| s.name = "StreemMapper" - s.version = "7.2.0" + s.version = "8.0.0" s.summary = "A JSON deserialization library for Swift" - s.homepage = "https://github.com/JustaLab/StreemMapper" + s.homepage = "https://github.com/stremsdoerfer/StreemMapper" s.license = "Apache License, Version 2.0" s.author = {"Keith Smiley" => "keithbsmiley@gmail.com", "Emilien Stremsdoerfer" => "emstre@gmail.com" } s.ios.deployment_target = "8.0" s.osx.deployment_target = "10.10" s.tvos.deployment_target = "9.0" s.watchos.deployment_target = "2.0" - s.source = { :git => "https://github.com/JustaLab/StreemMapper.git", :tag => s.version } + s.source = { :git => "https://github.com/stremsdoerfer/StreemMapper.git", :tag => s.version } s.requires_arc = true s.source_files = "Sources/*.swift" s.module_name = "StreemMapper" diff --git a/StreemMapperTests/ConvertibleValueTests.swift b/StreemMapperTests/ConvertibleValueTests.swift index 3caea54..17cedd6 100644 --- a/StreemMapperTests/ConvertibleValueTests.swift +++ b/StreemMapperTests/ConvertibleValueTests.swift @@ -60,7 +60,7 @@ final class ConvertibleValueTests: XCTestCase { struct Test: Mappable { let URLs: [URL]? init(map: Mapper) { - self.URLs = map.from(field: "urls") + self.URLs = map.optionalFrom(field: "urls") } } @@ -72,7 +72,7 @@ final class ConvertibleValueTests: XCTestCase { struct Test: Mappable { let URLs: [URL]? init(map: Mapper) { - self.URLs = map.from(field: "urls") + self.URLs = map.optionalFrom(field: "urls") } } @@ -96,7 +96,7 @@ final class ConvertibleValueTests: XCTestCase { struct Test: Mappable { let URLs: [URL]? init(map: Mapper) { - self.URLs = map.from(field: "urls") + self.URLs = map.optionalFrom(field: "urls") } } @@ -108,7 +108,7 @@ final class ConvertibleValueTests: XCTestCase { struct Test: Mappable { let URL: Foundation.URL? init(map: Mapper) { - self.URL = map.from(fields: ["a", "b"]) + self.URL = map.optionalFrom(fields: ["a", "b"]) } } @@ -120,7 +120,7 @@ final class ConvertibleValueTests: XCTestCase { struct Test: Mappable { let URL: Foundation.URL? init(map: Mapper) { - self.URL = map.from(fields: ["a", "b"]) + self.URL = map.optionalFrom(fields: ["a", "b"]) } } @@ -146,7 +146,7 @@ final class ConvertibleValueTests: XCTestCase { let dictionary: [String: Int]? init(map: Mapper) throws { - self.dictionary = map.from(field: "foo") + self.dictionary = map.optionalFrom(field: "foo") } } @@ -172,7 +172,7 @@ final class ConvertibleValueTests: XCTestCase { let dictionary: [String: Int]? init(map: Mapper) throws { - self.dictionary = map.from(field: "foo") + self.dictionary = map.optionalFrom(field: "foo") } } diff --git a/StreemMapperTests/CustomTransformationTests.swift b/StreemMapperTests/CustomTransformationTests.swift index c72f615..e9163b2 100644 --- a/StreemMapperTests/CustomTransformationTests.swift +++ b/StreemMapperTests/CustomTransformationTests.swift @@ -7,8 +7,8 @@ final class CustomTransformationTests: XCTestCase { let value: Int init(map: Mapper) throws { value = try map.from(field: "value", transformation: { thing in - if let a = thing as? Int { - return a + 1 + if let val = thing as? Int { + return val + 1 } else { return 0 } diff --git a/StreemMapperTests/MappableValueTests.swift b/StreemMapperTests/MappableValueTests.swift index ec0d6d5..4cbee4f 100644 --- a/StreemMapperTests/MappableValueTests.swift +++ b/StreemMapperTests/MappableValueTests.swift @@ -44,7 +44,7 @@ final class MappableValueTests: XCTestCase { struct Test: Mappable { let nest: Nested? init(map: Mapper) { - self.nest = map.from(field: "foo") + self.nest = map.optionalFrom(field: "foo") } } @@ -79,7 +79,7 @@ final class MappableValueTests: XCTestCase { struct Test: Mappable { let nests: [Nested]? init(map: Mapper) { - self.nests = map.from(field: "nests") + self.nests = map.optionalFrom(field: "nests") } } @@ -117,7 +117,7 @@ final class MappableValueTests: XCTestCase { struct Test: Mappable { let nests: [Nested]? init(map: Mapper) { - self.nests = map.from(field: "nests") + self.nests = map.optionalFrom(field: "nests") } } @@ -187,7 +187,7 @@ final class MappableValueTests: XCTestCase { struct Test: Mappable { let nests: [String: Nested]? init(map: Mapper) { - self.nests = map.from(field: "nests") + self.nests = map.optionalFrom(field: "nests") } } diff --git a/StreemMapperTests/OptionalValueTests.swift b/StreemMapperTests/OptionalValueTests.swift index 2679bd3..196f982 100644 --- a/StreemMapperTests/OptionalValueTests.swift +++ b/StreemMapperTests/OptionalValueTests.swift @@ -30,7 +30,7 @@ final class OptionalValueTests: XCTestCase { struct Test: Mappable { let string: [String]? init(map: Mapper) { - self.string = map.from(field: "foo") + self.string = map.optionalFrom(field: "foo") } } @@ -42,7 +42,7 @@ final class OptionalValueTests: XCTestCase { struct Test: Mappable { let strings: [String]? init(map: Mapper) { - self.strings = map.from(field: "strings") + self.strings = map.optionalFrom(field: "strings") } } @@ -54,7 +54,7 @@ final class OptionalValueTests: XCTestCase { struct Test: Mappable { let string: String? init(map: Mapper) throws { - self.string = map.from(fields: ["a", "b", "c" ]) + self.string = map.optionalFrom(fields: ["a", "b", "c" ]) } } @@ -66,7 +66,7 @@ final class OptionalValueTests: XCTestCase { struct Test: Mappable { let string: String? init(map: Mapper) { - self.string = map.from(fields: ["a", "b"]) + self.string = map.optionalFrom(fields: ["a", "b"]) } } diff --git a/StreemMapperTests/RawRepresentibleValueTests.swift b/StreemMapperTests/RawRepresentibleValueTests.swift index 60efe91..afa6c45 100644 --- a/StreemMapperTests/RawRepresentibleValueTests.swift +++ b/StreemMapperTests/RawRepresentibleValueTests.swift @@ -54,7 +54,7 @@ final class RawRepresentibleValueTests: XCTestCase { struct Test: Mappable { let value: Value? init(map: Mapper) { - self.value = map.from(field: "value") + self.value = map.optionalFrom(field: "value") } } @@ -70,7 +70,7 @@ final class RawRepresentibleValueTests: XCTestCase { struct Test: Mappable { let value: Value? init(map: Mapper) { - self.value = map.from(field: "value") + self.value = map.optionalFrom(field: "value") } } @@ -86,7 +86,7 @@ final class RawRepresentibleValueTests: XCTestCase { struct Test: Mappable { let value: Value? init(map: Mapper) { - self.value = map.from(field: "value") + self.value = map.optionalFrom(field: "value") } }