I used xcode 10.1
enum PriceType {
case cny
case usd
}
extension PriceType: ExpressibleByStringLiteral {
init(stringLiteral value: String) {
self.init(string: value)
}
init(unicodeScalarLiteral value: String) {
self.init(string: value)
}
init(extendedGraphemeClusterLiteral value: String) {
self.init(string: value)
}
init(string: String) {
switch string {
case "0":
self = .cny
case "1":
self = .usd
default:
switch Language.use {
case .cn(.hans):
self = "0"
case .en, .cn(.hant):
self = "1"
}
}
}
static var Symbol: String {
let priceStr: String = "0"
let priceType: PriceType = "priceType"
let priceType1: PriceType = priceStr // erorr: Cannot convert value of type 'String' to specified type 'PriceType'
return priceType.symbol
}
var symbol: String {
switch self {
case .cny:
return ""
case .usd:
return "$"
}
}
}
when biuld, line 29 is erorr : Cannot convert value of type 'String' to specified type 'PriceType'
I hope can use :
let priceStr: String = "0"
let priceType1: PriceType = priceStr
How can I do? or it's cann't?