if a Enum
type add new case
in new os version,how to check availability in switch
statement?
Like a Enum
in StoreKit
below
public enum Code : Int {
public typealias _ErrorType = SKError
case unknown
case clientInvalid
case paymentCancelled
case paymentInvalid
case paymentNotAllowed
case storeProductNotAvailable
@available(iOS 9.3, *)
case cloudServicePermissionDenied
@available(iOS 9.3, *)
case cloudServiceNetworkConnectionFailed
@available(iOS 10.3, *)
case cloudServiceRevoked
}
Is below code the only solution? It's too redundant.
if #available(iOS 10.3, *) {
switch code {
//all cases available in 10.3
...
}
} else if #available(iOS 9.3, *) {
switch code {
//all cases available in 9.3
...
}
} else {
switch code {
//all cases available below 9.3
...
}
}
-----------------new-------------------------
I think It's not a question. All cases writed in one switch
is fine, if
statement is unneccessary. Because new added cases would not called in low iOS version.