JHZ JHZ - 2 months ago 27
iOS Question

Does availability matter for Swift enums?

Swift requires me to add an

@available
annotation when using
CBManagerState
, an enumeration that was added in iOS 10.
CBManagerState
is just a replacement for
CBCentralManagerState
and
CBPeripheralManagerState
, and using the new replacement is fine in C-land, since enums are just integers.

If I want to support iOS 9, is this also safe in Swift 2.3, or should I stick with the deprecated versions?

JAL JAL
Answer

Yes, availability matters for all symbols in the SDK. The issue isn't that the numbers aren't available in iOS versions less than 10, but the actual CBManagerState symbol is not available.

If you are targeting iOS 9, use the symbols and enums available to you in that SDK (what you are calling the "deprecated" types). If you specifically want to support an iOS 10 feature, use an availability check for the iOS 10 feature or version and fall back on iOS 8/9 functionality if the conditions of your check are not met.