//: Playground - noun: a place where people can play
import UIKit
var str = "字典"
//声明一个字典
var dic: Dictionary<String,String> = ["1001":"1","1002":"2","1003":"3"]
var num = dic["1001"]
//向字典中添加键值
var student: Dictionary<Int,String> = [1001:"小明",1002:"小六",1003:"小杰"]
student[1004] = "小鹏"
student
//修改
student.updateValue("小威", forKey: 1001)
student
//删除
student.removeValueForKey(1001)
student
//获得值
let value = student[1002]
//遍历
for (key, value) in student {
println("key:\(key),value:\(value)")
}
for tuples in student {
println("key:\(tuples.0),value:\(tuples.1)")
}
//遍历key
for key in student.keys {
println("key:\(key)")
}
//遍历value
for value in student.values {
println("value:\(value)")
}
switch 1 {
case 1:
println("123")
fallthrough
case 2:
println("456")
case 3:
println("789")
default:
println("3")
}