为什么(让key1:Keyword =“if”)顺利但(让key2:Keyword = String(“if”))出错?
public enum Keyword: String, ExpressibleByStringLiteral, ExpressibleByUnicodeScalarLiteral, ExpressibleByExtendedGraphemeClusterLiteral {
case `if` = "if"
case `else` = "else"
public init(stringLiteral:String){
self.init(rawValue: stringLiteral)!
}
public init(unicodeScalarLiteral value: String) {
self.init(rawValue: value)!
}
public init(extendedGraphemeClusterLiteral value: String) {
self.init(rawValue: value)!
}
}
let key1:Keyword = "if" //going well
let key2:Keyword = String("if") //error reported