zoukankan      html  css  js  c++  java
  • Swift 字典

    /*********************************************************
                        Swift 字典
    *********************************************************/
    
    var dictionary  = ["name":"LJF","age":"100"]
    println(dictionary)
    //1、字典键值对的添加
    dictionary["height"] = "175"
    println(dictionary)
    //2、字典键值对的删除
    dictionary.removeValueForKey("height")
    println(dictionary)
    //3、字典键值对的改动
    //3.1使用键,改动固定键的相应值
    dictionary["name"] = "TXM"
    println(dictionary)
    //3.2使用updateValue方法进行改动也能够加入键值对。当填入的键存在时就会对旧值的更新,不存在时返回nil  当键不存在的时候就会进行加入
    let returnValue = dictionary.updateValue("99", forKey: "age")
    let returnValue2 = dictionary.updateValue("99", forKey: "age1")
    println("returnValue = (returnValue)","dictionary = (dictionary)")
    println("returnValue = (returnValue2)","dictionary = (dictionary)")
    //3.3字典键值对的查询(字典遍历)
    for (key , value) in dictionary{
        println("key = (key)","value = (value)")
    }
    //4字典初始化的方式也有两种   使用字典初始化方式进行创建的是固定键值类型的字典
    //4.1 
    var initDictionary:[String:String] = [String :String]()
    var initDictionary2:Dictionary<String, String> = Dictionary()
    
    /*Swift和OC中集合对照
    在OC中。我们经常使用的数组和字典都是引用类型,而Swift中是值类型,这是由于在Swift中,这些结合类的底层都是struct
    枚举值类型。函数,闭包是引用类型
    */
  • 相关阅读:
    SQL Server游标
    SQL Server中的事务与锁(帮助理解,优化,很细致)
    T-sql语句查询执行顺序
    安装odoo过程中出现的问题
    odoo继承父类中的函数(方法)
    linux qt下 QSqlDatabase: QMYSQL driver not loaded
    odoo学习:创建新数据库及修改数据库内容
    登录mysql出现/var/lib/mysql/mysql.sock不存在
    odoo学习记录1
    zzUbuntu安装配置Qt环境
  • 原文地址:https://www.cnblogs.com/mfmdaoyou/p/7055927.html
Copyright © 2011-2022 走看看