swift 枚举类型

前端之家收集整理的这篇文章主要介绍了swift 枚举类型前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


//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

猜你在找的Swift相关文章