标签:
学习地址:http://www.rm5u.com/ 或 http://www.runoob.com/
import UIKit var someDict:[Int:String] = [1:"One", 2:"Two", 3:"Three"] for (key, value) in someDict { print("字典 key \(key) - 字典 value \(value)") }
也可以使用enumerate()方法来进行字典遍历,返回的是字典的索引及 (key, value) 对:
import UIKit var someDict:[Int:String] = [1:"One", 2:"Two", 3:"Three"] for (key, value) in someDict.enumerate() { print("字典 key \(key) - 字典 (key, value) 对 \(value)") }
· 字典转换为数组:
可以提取字典的键值(key-value)对,并转换为独立的数组:
let dictKeys = [Int](someDic.keys)
let dictValues = [String](someDic.values)
· count 属性
· isEmpty 属性
标签:
原文地址:http://www.cnblogs.com/ifish1990/p/5845504.html