当前位置: 代码迷 >> 综合 >> swift 枚举类型
  详细解决方案

swift 枚举类型

热度:45   发布时间:2023-12-15 01:26:51.0


//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?.rawValuelet btn = UIButton()
btn.setTitle("test", for: .normal)//3.给枚举类型进行赋值
enum Direction : Int{case east = 0case west = 1case north = 2case south = 3
}let d:Direction = .east//east
let d2 = Direction(rawValue:1) //west//4. 枚举类型定义方式二enum type : Int{case east = 0 ,west ,north, south
}