源代码:
//
//遍历字典.swift
//
// Created by chenzhen on 16/8/2.
// From 大连东软信息学院
// Copyright © 2016年 zhen7216. All rights reserved.
//
import Foundation
var studentDictionary = [102 : "张三", 105 : "李四", 109 : "王五"]
print("---遍历键---")
for studentID in studentDictionary.keys {
print("学号: \(studentID)")
}
print("---遍历值---")
for studentName in studentDictionary.values {
print("学生:\(studentName)")
}
print("---遍历键: 值---")
for (studentID, studentName) in studentDictionary {
print("\(studentID) : \(studentName)")
}
运行结果: