swift Dictionary操作
来源:互联网 发布:pdf文件分割软件 编辑:程序博客网 时间:2024/06/05 22:52
定义字典Dictionary<String,AnyObject>,Dictionary<String,String>:key一般是String类型,如果value类型统一
//Dictionary:定义swift字典
var dictTest:Dictionary<String,AnyObject> = ["name":"Hellen","age":12]
//向字典添加值
dictTest["number"] =1002
dictTest["height"] =178.5
dictTest["weight"] =56
print(dictTest)
//["height": 178.5, "age": 12, "number": 1002, "weight": 56, "name": Hellen]
dictTest.indexForKey("name")
print(dictTest.indexForKey("name"))
//更新数据
dictTest.updateValue(178, forKey:"number")
print(dictTest)
//["age": 12, "number": 178, "name": Hellen]
//移除数据
dictTest.removeValueForKey("age")
print(dictTest)
//["number": 178, "name": Hellen]
print("dictTest =\(dictTest) and name =\(dictTest["name"]) and age =\(dictTest["age"])")
也可以转换成NSDictionary操作
var nsdict:NSDictionary =dictTest as NSDictionary
print("nsdict =\(nsdict) and name =\(nsdict["name"]) and age =\(nsdict["age"])")
print("nsdict =\(nsdict) and name =\(nsdict.objectForKey("name")) and age =\(nsdict.objectForKey("age"))")
- swift Dictionary操作
- Swift-Dictionary
- swift Dictionary 字典
- Swift 字典Dictionary
- swift中的字典Dictionary
- Swift 字典Dictionary
- swift 学习笔记 --> Dictionary
- swift-array-dictionary
- Swift - Dictionary 基本使用
- Swift 字典(Dictionary)
- swift-字典(Dictionary)
- Swift中Dictionary
- iOS - Swift Dictionary 字典
- Swift-字典(Dictionary)
- swift Dictionary 字典学习
- Swift 中的字典 (Dictionary)
- Swift学习笔记-字典Dictionary
- swift dictionary 是否存在key
- Service启动模式
- linux下的定时任务cron
- opencv 内存中读取一段jpg 图片
- iOS 模糊效果的实现
- FFPlay视频播放流程
- swift Dictionary操作
- 今天做错的笔试题:StringBuffer引用传参
- Linux套接字通信常用函数-accept
- android安全
- CoreGraphics框架中的CGAffineTransform
- ScrollView和ListView嵌套发生错误的问题
- 排序
- jquery解释django+ajax+json的数据
- MySQL存储引擎MyISAM VS InnoDB