美文网首页swiftswift 文章收集
swift基础语法(八)——元祖

swift基础语法(八)——元祖

作者: 芝麻绿豆 | 来源:发表于2016-02-06 21:16 被阅读35次

    介绍

    • 元组是Swift中特有的
    • 它是:
      • 它是一种数据结构,在数学中应用广泛。
    • 类似于数组或者字典
    • 可以用于定义一组数据

    定义

    元祖的常见写法有两种

    ("001", "alin", 90, 70)
    (id:"001", name:"ly", english_score:100, chinese_score:98)
    

    基本操作

    // 元祖:HTTP错误
    //数组
    // let array = [404, "Not Found"]
    // 写法一:
    let error = (404, "Not Found")
    print(error.0)
    print(error.1)
    // 写法二:
    let error = (errorCode : 404, errorInfo : "Not Found")
    print(error.errorCode)
    print(error.errorInfo)
    // 写法三:
    let (errorCode, errorIno) = (404, "Not Found")
    print(errorCode)
    print(errorIno)
    

    相关文章

      网友评论

        本文标题:swift基础语法(八)——元祖

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