URLSessionTask.priority
is a floating-point value between 0.0 (lowest) and 1.0 (highest).
Task.Priority
could use similar names and raw values. For example:
extension Task {
public struct Priority: Hashable, RawRepresentable {
public static let lowest: Self = 0.0 // background
public static let low: Self = 0.25 // utility
public static let medium: Self = 0.5 // default
public static let high: Self = 0.75 // userInitiated
public static let highest: Self = 1.0 // userInteractive
public typealias RawValue = Float32
public let rawValue: RawValue
public init(rawValue: RawValue) {
self.rawValue = rawValue // FIXME: rawValue.clamped(to: 0...1)
}
}
}
extension Task.Priority: ExpressibleByFloatLiteral {
public typealias FloatLiteralType = RawValue
public init(floatLiteral rawValue: RawValue) {
self.init(rawValue: rawValue)
}
}
extension Task.Priority: Comparable {
public static func < (_ lhs: Self, _ rhs: Self) -> Bool {
lhs.rawValue < rhs.rawValue
}
}