diff --git a/Source/ConstraintPriority.swift b/Source/ConstraintPriority.swift index 7299fa9..f9dab16 100644 --- a/Source/ConstraintPriority.swift +++ b/Source/ConstraintPriority.swift @@ -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 + } } diff --git a/Tests/Tests.swift b/Tests/Tests.swift index ed6df40..e232fcc 100644 --- a/Tests/Tests.swift +++ b/Tests/Tests.swift @@ -539,5 +539,10 @@ class SnapKitTests: XCTestCase { XCTAssertEqual(self.container.snp_constraints.count, 1, "Should have 1 constraint") 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) + } }