如果Enum
类型在新的操作系统版本中添加新case
,如何在switch
声明查询? 像StoreKit
一个Enum
低于空房情况
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
}
是下面的代码是唯一的解决办法?这太冗余了。
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 -------------------------
我想这不是问题。所有在一个switch
中编写的例子都没有问题,if
语句是不必要的。因为新的附加案例不会在低iOS版本中调用。