Unavailable Condition

Use #unavailable/#available instead of #available/#unavailable with an empty body.

  • Identifier: unavailable_condition
  • Enabled by default: Yes
  • Supports autocorrection: No
  • Kind: idiomatic
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.6.0
  • Default configuration:
    KeyValue
    severity warning

Non Triggering Examples

if #unavailable(iOS 13) {
  loadMainWindow()
}
if #available(iOS 9.0, *) {
  doSomething()
} else {
  legacyDoSomething()
}
if #available(macOS 11.0, *) {
   // Do nothing
} else if #available(macOS 10.15, *) {
   print("do some stuff")
}

Triggering Examples

if #available(iOS 14.0) {

} else {
  oldIos13TrackingLogic(isEnabled: ASIdentifierManager.shared().isAdvertisingTrackingEnabled)
}
if #available(iOS 14.0) {
  // we don't need to do anything here
} else {
  oldIos13TrackingLogic(isEnabled: ASIdentifierManager.shared().isAdvertisingTrackingEnabled)
}
if #available(iOS 13, *) {} else {
  loadMainWindow()
}
if #unavailable(iOS 13) {
  // Do nothing
} else if i < 2 {
  loadMainWindow()
}