在Swift2中,您可以编写类似以下代码的内容:
switch productIdentifier {
case hasSuffix("q"):
return "Quarterly".localized
case hasSuffix("m"):
return "Monthly".localized
default:
return "Yearly".localized
}
并且它可以工作。在 Swift 3 中,我唯一能使上述代码工作的方法是:
switch productIdentifier {
case let x where x.hasSuffix("q"):
return "Quarterly".localized
case let x where x.hasSuffix("m"):
return "Monthly".localized
default:
return "Yearly".localized
}
这似乎失去了Swift2版本的清晰度,让我觉得自己错过了什么。当然,以上只是一个简单的版本。我很好奇是否有更好的处理方法?