Swift 3, switch statement, case hasPrefix
I don't know if this is any better than using value binding as in your example, but you can just use an underscore instead,
switch productIdentifier {
case _ where productIdentifier.hasSuffix("q"):
return "Quarterly".localized
case _ where productIdentifier.hasSuffix("m"):
return "Monthly".localized
default:
return "Yearly".localized
You seem to be only checking the last character of the productIdentifier
. You could do it this way:
switch productIdentifier.last {
case "q"?:
return "Quarterly".localized
case "m"?:
return "Monthly".localized
default:
return "Yearly".localized
}