「Swift」辞書(dictionary)の全てkey、valueを取得する
書式
Array(辞書名.keys)
Array(辞書名.values)
使用例
//dictionaryを定義 let student: [String: Any] = [ "name": "yamada", "age": 26, "addr": "tokyo", "weight": 68.25 ] //Arrayでkeyとvalueを取得 print("辞書のkeys:") print(Array(student.keys)) print("辞書のvalues:") print(Array(student.values))
結果
$ swift dmm.swift
辞書のkeys:
[“name", “age", “weight", “addr"]
辞書のvalues:
[“yamada", 26, 68.25, “tokyo"]