Skip to content

Commit

Permalink
Merge pull request #11 from PersistX/xcode-9.3
Browse files Browse the repository at this point in the history
Xcode 9.3 / Swift 4.1
  • Loading branch information
mdiep authored Apr 29, 2018
2 parents b3847c0 + 29bf31a commit 5d21aa3
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: objective-c
osx_image: xcode9.2
osx_image: xcode9.3
branches:
only:
- master
Expand Down
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "antitypical/Result" ~> 3.2.1
github "antitypical/Result" ~> 4.0
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github "PersistX/Standards" "dc5f17bb068261693720ef6bab3272d4d7c71fce"
github "antitypical/Result" "3.2.1"
github "antitypical/Result" "4.0.0"
10 changes: 7 additions & 3 deletions Schemata.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 0900;
LastUpgradeCheck = 0930;
ORGANIZATIONNAME = PersistX;
TargetAttributes = {
BE64E7191EA3AF4D0047D035 = {
Expand Down Expand Up @@ -511,13 +511,15 @@
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_DOCUMENTATION_COMMENTS = YES;
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 @@ -570,13 +572,15 @@
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_DOCUMENTATION_COMMENTS = YES;
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 @@ -681,7 +685,7 @@
buildSettings = {
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -706,7 +710,7 @@
buildSettings = {
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0920"
LastUpgradeVersion = "0930"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,7 +26,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -56,7 +55,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
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 = "0930"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
8 changes: 8 additions & 0 deletions Schemata.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
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>
84 changes: 41 additions & 43 deletions Sources/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,54 +71,52 @@ extension Int: ModelValue {
public static let value = Value<Int, Int>()
}

#if swift(>=4.1)
extension Optional: ModelValue where Wrapped: ModelValue {
public typealias Encoded = Wrapped.Encoded?

public static var value: Value<Wrapped.Encoded?, Wrapped?> {
return Value(
decode: { encoded in
switch encoded {
case nil:
return .success(nil)
case let .some(value):
return Wrapped.value.decode(value).map(Optional.some)
}
},
encode: { $0.map(Wrapped.value.encode) }
)
}

public static var anyValue: AnyValue {
return AnyValue(
encoded: Wrapped.anyValue.encoded,
encode: { value in
// swiftlint:disab'le:next force_cast
(value as? Wrapped).map(Wrapped.anyValue.encode) ?? .null
},
decoded: Wrapped?.self,
decode: { primitive -> Result<Any, ValueError> in
if primitive == .null {
return .success(Wrapped?.none as Any)
}
return Wrapped.anyValue
.decode(primitive)
// swiftlint:disable:next force_cast
.map { Optional($0 as! Wrapped) as Any }
extension Optional: Hashable, AnyModelValue, ModelValue where Wrapped: ModelValue {
public typealias Encoded = Wrapped.Encoded?

public static var value: Value<Wrapped.Encoded?, Wrapped?> {
return Value(
decode: { encoded in
switch encoded {
case nil:
return .success(nil)
case let .some(value):
return Wrapped.value.decode(value).map(Optional.some)
}
)
}
},
encode: { $0.map(Wrapped.value.encode) }
)
}

public var hashValue: Int {
switch self {
case .none:
return 0
case let .some(value):
return value.hashValue
public static var anyValue: AnyValue {
return AnyValue(
encoded: Wrapped.anyValue.encoded,
encode: { value in
// swiftlint:disab'le:next force_cast
(value as? Wrapped).map(Wrapped.anyValue.encode) ?? .null
},
decoded: Wrapped?.self,
decode: { primitive -> Result<Any, ValueError> in
if primitive == .null {
return .success(Wrapped?.none as Any)
}
return Wrapped.anyValue
.decode(primitive)
// swiftlint:disable:next force_cast
.map { Optional($0 as! Wrapped) as Any }
}
)
}

public var hashValue: Int {
switch self {
case .none:
return 0
case let .some(value):
return value.hashValue
}
}
#endif
}

extension String: ModelValue {
public static let value = Value<String, String>()
Expand Down
2 changes: 1 addition & 1 deletion Sources/Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Result
private extension DecodeError {
init(_ errors: DecodeError?...) {
self = errors
.flatMap { $0 }
.compactMap { $0 }
.reduce(DecodeError([:]), +)
}
}
Expand Down
70 changes: 34 additions & 36 deletions Tests/ModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,50 +32,48 @@ class UUIDModelValueTests: XCTestCase {
}
}

#if swift(>=4.1)
class OptionalModalValueTests: XCTestCase {
func testDecodeNil() {
XCTAssertNil(UUID?.value.decode(nil).value!)
}
class OptionalModalValueTests: XCTestCase {
func testDecodeNil() {
XCTAssertNil(UUID?.value.decode(nil).value!)
}

func testDecodeWrapped() {
XCTAssertEqual(UUID?.value.decode(uuid.uuidString).value, uuid)
}
func testDecodeWrapped() {
XCTAssertEqual(UUID?.value.decode(uuid.uuidString).value, uuid)
}

func testDecodeFailure() {
XCTAssertNotNil(UUID?.value.decode("junk").error)
}
func testDecodeFailure() {
XCTAssertNotNil(UUID?.value.decode("junk").error)
}

func testEncodeNil() {
XCTAssertNil(UUID?.value.encode(nil))
}
func testEncodeNil() {
XCTAssertNil(UUID?.value.encode(nil))
}

func testEncodeWrapped() {
XCTAssertEqual(UUID?.value.encode(uuid), uuid.uuidString)
}
func testEncodeWrapped() {
XCTAssertEqual(UUID?.value.encode(uuid), uuid.uuidString)
}
}

class OptionalModalAnyValueTests: XCTestCase {
func testDecodeNil() {
let result = UUID?.anyValue.decode(.null)
XCTAssertEqual(result.value! as? UUID, nil)
}
class OptionalModalAnyValueTests: XCTestCase {
func testDecodeNil() {
let result = UUID?.anyValue.decode(.null)
XCTAssertEqual(result.value! as? UUID, nil)
}

func testDecodeWrapped() {
XCTAssertEqual(UUID?.anyValue.decode(.string(uuid.uuidString)).value as? UUID, uuid)
}
func testDecodeWrapped() {
XCTAssertEqual(UUID?.anyValue.decode(.string(uuid.uuidString)).value as? UUID, uuid)
}

func testDecodeFailure() {
XCTAssertNotNil(UUID?.anyValue.decode(.string("junk")).error)
}
func testDecodeFailure() {
XCTAssertNotNil(UUID?.anyValue.decode(.string("junk")).error)
}

func testEncodeNil() {
let anyValue = UUID?.anyValue
XCTAssertEqual(anyValue.encode(UUID?.none as Any), .null)
}
func testEncodeNil() {
let anyValue = UUID?.anyValue
XCTAssertEqual(anyValue.encode(UUID?.none as Any), .null)
}

func testEncodeWrapped() {
XCTAssertEqual(UUID?.anyValue.encode(uuid), .string(uuid.uuidString))
}
func testEncodeWrapped() {
XCTAssertEqual(UUID?.anyValue.encode(uuid), .string(uuid.uuidString))
}
#endif
}

0 comments on commit 5d21aa3

Please sign in to comment.