美文网首页
Swift 字典 结构体 枚举

Swift 字典 结构体 枚举

作者: CaptainRoy | 来源:发表于2019-06-14 13:37 被阅读0次
    • 申明一个空字典
    var dictionary = [Int:String]()
    
    // [0: "zero", 1: "one"]
    var dictionary = [Int:String]()
    dictionary[0] = "zero"
    dictionary[1] = "one"
    
    • 字典置空
    dictionary = [:]
    
    • 结构体
    struct BookInfo {
        var id = 0
        var name = ""
        var author = ""
        var type = ""
    }
    var book = BookInfo(id: 10010, name: "swift", author: "apple", type: "education")
    
    • 枚举
    enum CompassPoint {
        case north
        case south
        case east
        case west
    }
    
    enum HttpStatusCode : Int {
        case HttpFail = 0
        case HttpNormal = 200
        case HttpSuccess = 202
    }
    
    print(CompassPoint.east)
    print(HttpStatusCode.HttpNormal)
    

    相关文章

      网友评论

          本文标题:Swift 字典 结构体 枚举

          本文链接:https://www.haomeiwen.com/subject/ntasfctx.html