zoukankan      html  css  js  c++  java
  • swift -- Tuple 元组 Dictionary

    // 定义一个空的Dictionary

    var dict1 = Dictionary<Int, String>()

    var dict2:Dictionary<Int, String> = [:]

    var dict3 = [:]

    // 定义一个空的Tuple

    var tuple1: () = ()

    var tuple2:(Int, String) = (5, "As god name")

    let tuple1 = ("As god name", "2015/08/08", true, 16)    // 定义元组

    let tuple3 = (name: "As god name", time: "08/08", bool: true, number: 10)   // 定义元组

    let login: (Bool, String) = (true, "慕课网")          // 定义元组

    let tuple2 = ("program", "swift")

    let (name, time, isBool, number) = tuple1

    name

    time

    isBool

    number

    tuple1.0

    tuple1.1

    tuple1.2

    tuple1.3

    // Dictionary

    var dictionary = [1:"A", 2:"Swift", 3:"ios"]

    var dictionary2:[Int:String] = [9:"Hello", 10:"dingding"]

    var dictionary3:Dictionary<String, String> = ["搜索引擎" : "Google", "新闻网站" : "网易新闻"]

    tuple3.name

    tuple3.time

    tuple3.bool

    tuple3.number

    var dict1 = ["program" : "swift", "study" : "ios", "address" : "ShangHai"]

    var dict2:[Int:String] = [10:"慕课网", 11:"百度", 15:"Google"]

    var dict3:Dictionary<String, String> = ["学习网站" : "慕课网", "培训机构" : "传智播客", "所在地" : "北京"]

    dict1["hobby"] = "sport"

    dict1

    dict1.removeValueForKey("address")

    dict1

    dict2.removeValueForKey(10)

    dict2

    for (key, value) in dict2{

        println("(key) : (value)")

    }

    dict2.keys

    dict2.values

    dict2

    var dict1:[String:String] = ["ding":"dingding", "xing":"xingxing", "yu":"yuyuyu"]

    for key in dict1.keys{

        println(key)

    }

    for value in dict1.values{

        println(value)

    }

    Array(dict1.keys)

    [String](dict1.keys)

    [String](dict1.values)

    Array(dict1.values)

    let colors = [

        "Air Force Blue" : (red:93, green:138, blue:168),

        "Bittersweel" : (red:254, green:111, blue:94)

    ]

    let base = 2

    let power = 10

    var result = 1

    for _ in 1...power{    

        result = base*result

    }

    result

  • 相关阅读:
    使用watch定时执行命令并显示结果
    LVS配置
    myeclipse通过查询源码查询方法
    导入struts2框架项目无法运行tomcat
    解决eclipse/myeclipse导入项目时出现红色叹号的方法
    my/eclipse中的debug调试
    导入项目后servlet报错
    转到Servlet出现500型错误
    关于快捷键导包失败
    关于jsp找不到servlet
  • 原文地址:https://www.cnblogs.com/lianfu/p/4714107.html
Copyright © 2011-2022 走看看