mirror of https://github.com/SnapKit/SnapKit
Add `Strideble` conformance to `ConstraintPriority ` (#409)
This enables sugar like: `.priority(.low + 1)`
This commit is contained in:
parent
be172a3f0f
commit
ff97375b22
|
@ -27,8 +27,7 @@
|
||||||
import AppKit
|
import AppKit
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
public struct ConstraintPriority : ExpressibleByFloatLiteral, Equatable, Strideable {
|
||||||
public struct ConstraintPriority : ExpressibleByFloatLiteral, Equatable {
|
|
||||||
public typealias FloatLiteralType = Float
|
public typealias FloatLiteralType = Float
|
||||||
|
|
||||||
public let value: Float
|
public let value: Float
|
||||||
|
@ -65,4 +64,14 @@ public struct ConstraintPriority : ExpressibleByFloatLiteral, Equatable {
|
||||||
public static func ==(lhs: ConstraintPriority, rhs: ConstraintPriority) -> Bool {
|
public static func ==(lhs: ConstraintPriority, rhs: ConstraintPriority) -> Bool {
|
||||||
return lhs.value == rhs.value
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -540,4 +540,9 @@ class SnapKitTests: XCTestCase {
|
||||||
XCTAssertEqual(self.container.snp_constraints.first?.priority, ConstraintPriority.low.value + 1)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue