Skip to content

Instantly share code, notes, and snippets.

@MP0w
Last active February 16, 2017 22:01
Show Gist options
  • Save MP0w/4cd6df5558f8db2729035c0a25203398 to your computer and use it in GitHub Desktop.
Save MP0w/4cd6df5558f8db2729035c0a25203398 to your computer and use it in GitHub Desktop.
Add Strideble to ConstraintPriority
//: 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