1. KeyValuePairs
- 배열처럼 순서가 있는 딕셔너리
- key값이 Hashable일 필요없음(검색 알고리즘상 빠르지 않음)
- key값이 동일한 것도 가능
- ‘: KeyValuePairs’ 타입을 반드시 적어야함
let introduce: KeyValuePairs = ["first": "Hello", "second": "My Name", "third":"is"]
1) 요소에 접근
- 배열처럼 인덱스로 접근 가능
- 요소에서는 튜플방식으로 접근
let introduce: KeyValuePairs = ["first": "Hello", "second": "My Name", "third":"is"]
introduce[0]
introduce[0].0
introdue[0].1
print("\(introduce[0].key)는 \(introduce[0].value) 입니다.")
print("\(introduce[1].key)는 \(introduce[1].value) 입니다.")
print("\(introduce[2].key)는 \(introduce[1].value) 입니다.")
2) 반복문과의 결합
- KeyValuePairs 순서가 있기 때문에 순서에 맞게 나옴
let introduce: KeyValuePairs = ["first": "Hello", "second": "My Name", "third":"is"]
for value in introduce {
print("\(value.key)는 \(value.value) 입니다.")
}
3) append, remove 같은 기능은 없음