I'm working with new asleep values from HealthKit which are available since iOS 16. My app supports iOS 15+. Is there any reason why if statements with == need an API availability check while switch/case statements do not? Is it safe to use it in a switch statement without availability check?
guard let value = HKCategoryValueSleepAnalysis(rawValue: sample.value) else { return nil }
if value == .asleepREM { // 'asleepREM' is only available in iOS 16.0 or newer
}
if case asleepREM = value { // no error
}
switch value { // no error
case .asleepREM:
break
default:
break
}
