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
    枚举值类型。函数,闭包是引用类型
    */
  • 相关阅读:
    对象和接口简单比较
    DevExpress报表开发基本流程
    有关ExecuteNonQuery返回值的分析
    2012年度计划
    小测试:有关++i&&i++,你是不是看晕了
    “PE文件格式”1.9版 完整译文
    .NET中的入口及幕后英雄:MSCorEE.dll(转)
    软件构建过程中的隐喻
    转:地图导出格式,教你如何选择
    推荐几个网站
  • 原文地址:https://www.cnblogs.com/mfmdaoyou/p/7055927.html
Copyright © 2011-2022 走看看