美文网首页
Ios 元组类型

Ios 元组类型

作者: 人鱼小姐没有腿 | 来源:发表于2019-07-17 17:02 被阅读0次

    import UIKit

    var point = (5,2) //元祖类型为Int类型
    var httpResponse = (404,"Not Found") //元祖类型为Int和String

    var point2 :(Int, Int, Int) = ( 5 , 5 , 2)
    var httpResponse2 :(Int,String) = (200, "OK")

    let (statusCode , statusMessage) = httpResponse2
    print(statusCode)
    print(statusMessage)

    //命名元组分量的隐式写法
    let point3 = (x:1,y:2)
    point3.x
    point3.y

    //命名元组分量的显示写法
    let point4:(x:Int,y:Int) = (222,444)
    point4.x
    point4.y

    //元祖解包写法 用下划线代表忽略这个值
    let loginResponse = (true,"loginName")
    let (isLogin,
    ) = loginResponse
    if isLogin{
    print("登陆成功")
    }else{
    print("登陆失败")
    }

    //使用print打印字符串差值
    let a = 2
    let b = 3

    print("(a) * (b) = (a*b)")

    相关文章

      网友评论

          本文标题:Ios 元组类型

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