zoukankan      html  css  js  c++  java
  • Swift 元组 Tuple

    let infoArray:[Any] = ["jack",18,1.88]

    let infoName=infoArray[0] as!String //此处为Any类型强转为String类型

    print(infoName.count)

     

     

    let infoDict:[String:Any]=["name":"jack","age":18]

    let dictName=infoDict["name"] as! String //此处为Any类型强转为String类型

    print(dictName.count)

     

    //使用数组或者字典取出的类型为Any类型

    //使用元组保存信息,能头准确的推导出数据类型

    //写法一:

    let infoTuple1=("jack",18,1.88)

    let tupleName=infoTuple1.0

    let tupleAge = infoTuple1.1

    let tupleHeight = infoTuple1.2

     

    //写法二:使用别名

    let infoTuple2=(name:"jack",age:18,height:1.88)

    print(infoTuple2.name)

    print(infoTuple2.age)

     

    //写法三:

    let (name,age,height) = ("jack",18,1.88)

    print(name)

  • 相关阅读:
    免费的视频、音频转文本
    Errors are values
    Codebase Refactoring (with help from Go)
    Golang中的坑二
    Cleaner, more elegant, and wrong(msdn blog)
    Cleaner, more elegant, and wrong(翻译)
    Cleaner, more elegant, and harder to recognize(翻译)
    vue控制父子组件渲染顺序
    computed 和 watch 组合使用,监听数据全局数据状态
    webstorm破解方法
  • 原文地址:https://www.cnblogs.com/dhui69/p/11157377.html
Copyright © 2011-2022 走看看