Add `Strideble` conformance to `ConstraintPriority ` (#409)

This enables sugar like: `.priority(.low + 1)`
This commit is contained in:
Alex Manzella 2017-02-22 03:07:09 +01:00 committed by Robert Payne
parent be172a3f0f
commit ff97375b22
2 changed files with 17 additions and 3 deletions

View File

@ -27,8 +27,7 @@
import AppKit
#endif
public struct ConstraintPriority : ExpressibleByFloatLiteral, Equatable {
public struct ConstraintPriority : ExpressibleByFloatLiteral, Equatable, Strideable {
public typealias FloatLiteralType = Float
public let value: Float
@ -65,4 +64,14 @@ public struct ConstraintPriority : ExpressibleByFloatLiteral, Equatable {
public static func ==(lhs: ConstraintPriority, rhs: ConstraintPriority) -> Bool {
return lhs.value == rhs.value
}
// MARK: Strideable
public func advanced(by n: FloatLiteralType) -> ConstraintPriority {
return ConstraintPriority(floatLiteral: value + n)
}
public func distance(to other: ConstraintPriority) -> FloatLiteralType {
return other.value - value
}
}

View File

@ -540,4 +540,9 @@ class SnapKitTests: XCTestCase {
XCTAssertEqual(self.container.snp_constraints.first?.priority, ConstraintPriority.low.value + 1)
}
func testPriorityStride() {
let highPriority: ConstraintPriority = .high
let higherPriority: ConstraintPriority = .high + 1
XCTAssertEqual(higherPriority.value, highPriority.value + 1)
}
}