枚举的和值的转换
enum SmileType: String {
case haha = "哈哈笑"
case hehe = "呵呵笑"
case heihei = "嘿嘿笑"
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let smileType: SmileType = .haha
print(smileType.rawValue) // 哈哈笑
let type = SmileType(rawValue: "哈哈笑")
print(type) // Optional(项目名称.SmileType.haha)
}
}
网友评论