• Swift


    //: Playground - noun: a place where people can play
    
    import UIKit
    
    // 元组就是将多个不同的值集合成一个数据
    /*
     元组是Objective-C中没有的数据类型,与数组类似,都是表示一组数据的集合,但与数组不同,它的特点是:
     特点: 1.可以有任意多个值 2.不同值可以是不同类型
    */
    
    var registrationResult = (isRegisterSuccess:true, nickName:"Rinpe", age:23, birthday:"1992年")
    let connectionResult = (404, "not found")
    
    // 获取元组中的数值(1)
    let (isRegisterSuccess, nickName, age, birthday) = registrationResult
    isRegisterSuccess
    nickName
    age
    birthday
    
    // 获取元组中的数值(2)
    registrationResult.0
    registrationResult.1
    registrationResult.2
    registrationResult.3
    
    // 获取元组中的数值(3)
    registrationResult.isRegisterSuccess
    registrationResult.nickName
    registrationResult.age
    registrationResult.birthday
    
    
    // 使用下划线_忽略部分数值
    let loginResult:(Bool, String) = (true, "Bobo")
    let (isLoginSuccess, _) = loginResult
    if isLoginSuccess
    {
        print("登录成功")
    }
    
    /*
    可变元组和不可变元组
    用var定义的元组就是可变元组,let定义的就是不可变元组。不管是可变还是不可变元组, 元组在创建后就不能对其长度进行增加和删除之类的修改,只有可变元组能在创建之后修改元组中的数据
    需要注意的是,可变元组虽然可以修改数据,但却不能改变其数据的数据类型
    */
    

      

  • 相关阅读:
    ceph
    分布式网关层
    function declarations are hoisted and class declarations are not 变量提升
    js为Object对象动态添加属性和值 eval c.k c[k]
    方法就是一种变量
    static 不被实例调用
    WePY根据环境变量来改变运行时的参数
    函数类型实现接口——把函数作为接口来调用
    为什么需要onRoute函数?
    504 Gateway Timeout Error 502 Bad Gateway
  • 原文地址:https://www.cnblogs.com/Rinpe/p/5050517.html
Copyright © 2020-2023  润新知