50 lines
1.4 KiB
Swift
50 lines
1.4 KiB
Swift
|
|
import Foundation
|
|||
|
|
|
|||
|
|
/// The physical range band a user is open to connecting within.
|
|||
|
|
///
|
|||
|
|
/// Each tier maps to a different sensing technology. The tiers are ordered so
|
|||
|
|
/// higher tiers *include* lower ones (being open "in the area" also means
|
|||
|
|
/// you're open "nearby" and "right here").
|
|||
|
|
enum DistanceTier: Int, CaseIterable, Identifiable, Codable {
|
|||
|
|
/// 0–9 m. Ultra-wideband (Nearby Interaction). "This exact person."
|
|||
|
|
case rightHere = 1
|
|||
|
|
|
|||
|
|
/// 10–100 m. Bluetooth Low Energy / iBeacon. "This room, this block."
|
|||
|
|
case nearby = 2
|
|||
|
|
|
|||
|
|
/// 100 m–50 mi. Server-relayed, opt-in coarse location. "This neighborhood."
|
|||
|
|
case inTheArea = 3
|
|||
|
|
|
|||
|
|
var id: Int { rawValue }
|
|||
|
|
|
|||
|
|
var title: String {
|
|||
|
|
switch self {
|
|||
|
|
case .rightHere: return "Right Here"
|
|||
|
|
case .nearby: return "Nearby"
|
|||
|
|
case .inTheArea: return "In the Area"
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var subtitle: String {
|
|||
|
|
switch self {
|
|||
|
|
case .rightHere: return "0–9 m · UWB"
|
|||
|
|
case .nearby: return "10–100 m · BLE"
|
|||
|
|
case .inTheArea: return "100 m–50 mi · Network"
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// The primary engine used for this tier.
|
|||
|
|
var engine: ProximityEngine {
|
|||
|
|
switch self {
|
|||
|
|
case .rightHere: return .uwb
|
|||
|
|
case .nearby: return .ble
|
|||
|
|
case .inTheArea: return .beacon
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// Higher tiers include lower ones.
|
|||
|
|
func includes(_ other: DistanceTier) -> Bool {
|
|||
|
|
self.rawValue >= other.rawValue
|
|||
|
|
}
|
|||
|
|
}
|