Last active
February 16, 2017 22:01
-
-
Save MP0w/4cd6df5558f8db2729035c0a25203398 to your computer and use it in GitHub Desktop.
Add Strideble to ConstraintPriority
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import Foundation | |
public struct ConstraintPriority : ExpressibleByFloatLiteral, Equatable, Strideable { | |
public typealias FloatLiteralType = Float | |
public typealias Stride = Float | |
public let value: Float | |
public init(floatLiteral value: Float) { | |
self.value = value | |
} | |
public init(_ value: Float) { | |
self.value = value | |
} | |
public static var required: ConstraintPriority { | |
return 1000.0 | |
} | |
public static var high: ConstraintPriority { | |
return 750.0 | |
} | |
public static var low: ConstraintPriority { | |
return 250.0 | |
} | |
public static func ==(lhs: ConstraintPriority, rhs: ConstraintPriority) -> Bool { | |
return lhs.value == rhs.value | |
} | |
public func advanced(by n: Float) -> ConstraintPriority { | |
return ConstraintPriority(floatLiteral: value + n) | |
} | |
public func distance(to other: ConstraintPriority) -> Float { | |
return other.value - value | |
} | |
} | |
func priority(_ p: ConstraintPriority) -> Float { | |
return p.value | |
} | |
priority(600.0) | |
priority(.high) | |
priority(.high + 1) | |
priority(.low - 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment