Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions Mapper.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 */

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 = "";
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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";
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
28 changes: 11 additions & 17 deletions Mapper.xcodeproj/xcshareddata/xcschemes/StreemMapper.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
LastUpgradeVersion = "1150"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,38 +26,34 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C20174821BD5509D00E4FE18"
BuildableName = "StreemMapper.framework"
BlueprintName = "StreemMapper"
ReferencedContainer = "container:Mapper.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C201748C1BD5509D00E4FE18"
BlueprintIdentifier = "EBBAC36E1F95D0B9004E5286"
BuildableName = "StreemMapperTests.xctest"
BlueprintName = "StreemMapperTests"
ReferencedContainer = "container:Mapper.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C20174821BD5509D00E4FE18"
BuildableName = "StreemMapper.framework"
BlueprintName = "StreemMapper"
ReferencedContainer = "container:Mapper.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand All @@ -73,8 +69,6 @@
ReferencedContainer = "container:Mapper.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
2 changes: 1 addition & 1 deletion Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>7.2.0</string>
<string>8.0.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
Expand Down
4 changes: 2 additions & 2 deletions Sources/Mappable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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] {
Expand Down
20 changes: 10 additions & 10 deletions Sources/Mapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: RawRepresentable>(field: String) -> T? {
public func optionalFrom<T: RawRepresentable>(field: String) -> T? {
return try? self.from(field: field)
}

Expand Down Expand Up @@ -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<T: Mappable>(field: String) -> T? {
public func optionalFrom<T: Mappable>(field: String) -> T? {
return try? self.from(field: field)
}

Expand All @@ -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<T: Mappable>(field: String) -> [T]? {
public func optionalFrom<T: Mappable>(field: String) -> [T]? {
return try? self.from(field: field)
}

Expand Down Expand Up @@ -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<T: Convertible>(field: String) -> [T]? where T == T.ConvertedType {
public func optionalFrom<T: Convertible>(field: String) -> [T]? where T == T.ConvertedType {
return try? self.from(field: field)
}

Expand Down Expand Up @@ -353,7 +353,7 @@ public struct Mapper {
nil if anything throws
*/

public func from<U: Convertible, T: Convertible>(field: String) -> [U: T]? where U == U.ConvertedType, T == T.ConvertedType {
public func optionalFrom<U: Convertible, T: Convertible>(field: String) -> [U: T]? where U == U.ConvertedType, T == T.ConvertedType {
return try? self.from(field: field)
}

Expand Down Expand Up @@ -397,7 +397,7 @@ public struct Mapper {
nil if anything throws
*/

public func from<U: Convertible, T: Mappable>(field: String) -> [U: T]? where U == U.ConvertedType {
public func optionalFrom<U: Convertible, T: Mappable>(field: String) -> [U: T]? where U == U.ConvertedType {
return try? self.from(field: field)
}

Expand All @@ -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<T: Convertible>(fields: [String]) -> T? where T == T.ConvertedType {
public func optionalFrom<T: Convertible>(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
}
}
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -481,7 +481,7 @@ public struct Mapper {
*/

public func optionalFrom<T>(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
Expand Down
14 changes: 7 additions & 7 deletions Sources/Operators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public func |> <T: RawRepresentable>(map: Mapper, key: String) throws -> T {
}

public func |> <T: RawRepresentable>(map: Mapper, key: String) -> T? {
return map.from(field: key)
return map.optionalFrom(field: key)
}

public func |> <T: RawRepresentable>(map: Mapper, key: String) throws -> [T]
Expand Down Expand Up @@ -43,13 +43,13 @@ public func |> <T: Convertible>(map: Mapper, key: String) throws -> [T] where T
}

public func |> <T: Convertible>(map: Mapper, key: String) -> [T]? where T == T.ConvertedType {
return map.from(field: key)
return map.optionalFrom(field: key)
}

public func |> <U: Convertible, T: Convertible>(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 |> <U: Convertible, T: Convertible>(map: Mapper, key: String) throws -> [U: T]
Expand All @@ -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
Expand All @@ -73,19 +73,19 @@ public func |> <T: Mappable>(map: Mapper, key: String) throws -> T {
}

public func |> <T: Mappable>(map: Mapper, key: String) -> T? {
return map.from(field: key)
return map.optionalFrom(field: key)
}

public func |> <T: Mappable>(map: Mapper, key: String) throws -> [T] {
return try map.from(field: key)
}

public func |> <T: Mappable>(map: Mapper, key: String) -> [T]? {
return map.from(field: key)
return map.optionalFrom(field: key)
}

public func |> <U: Convertible, T: Mappable>(map: Mapper, key: String) -> [U: T]? where U == U.ConvertedType{
return map.from(field: key)
return map.optionalFrom(field: key)
}

public func |> <U: Convertible, T: Mappable>(map: Mapper, key: String) throws -> [U: T] where U == U.ConvertedType{
Expand Down
Loading