遍历字典

来源:互联网 发布:2017齐鲁软件大赛 编辑:程序博客网 时间:2024/06/06 07:35

源代码:

////遍历字典.swift////  Created by chenzhen on 16/8/2.//  From 大连东软信息学院//  Copyright © 2016年 zhen7216. All rights reserved.//import Foundationvar 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)")}

运行结果:


0 0