//1.枚举类型 enum MethodType :String{ case get = "get" case post = "post" case put = "put" case delete = "delete" } //2.创建枚举 let type1 : MethodType = .get let type2 = MethodType.post let type3 = MethodType(rawValue: "put")//put let strsde = type3?.rawValue let btn = UIButton() btn.setTitle("test",for: .normal) //3.给枚举类型进行赋值 enum Direction : Int{ case east = 0 case west = 1 case north = 2 case south = 3 } let d:Direction = .east//east let d2 = Direction(rawValue:1) //west //4. 枚举类型定义方式二 enum type : Int{ case east = 0,west,north,south }原文链接:https://www.f2er.com/swift/321491.html