为类添加字面量表达
class Persion :ExpressibleByStringLiteral{
let name :String
init(name value :String) {
self.name= value
}
required convenience init(stringLiteral value:String) {
self.init(name : value)
}
required convenience init(unicodeScalarLiteral value:String) {
self.init(name : value)
}
required convenience init(extendedGraphemeClusterLiteral value:String) {
self.init(name : value)
}
}
letp :Persion="xiaoming"
print(p.name)
网友评论