Get an Array of Dictionary's keys or values
If you need an array of keys or values of a dictionary, Swift has an easy way to do it.
1
2
3
4
5
6
7
8
// You can get an array of dictionary's key or values
let grades = ["KOR": 82, "ENG": 98, "MATH": 90]
let subjects = [String](grades.keys)
// ["KOR", "ENG", "MATH"]
let scores = [Int](grades.values)
// [82, 90, 90]
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.