- Value Type
- ๋ค๋ฅธ ๋ณ์์ ๋์
ํ๋ฉด ๋ณต์ฌ๋จ
- argument๋ก ๋๊ฒจ๋ ๋ณต์ฌ๋จ
- argument๋ก collection์ ๋๊ฒจ์ ๋ณํ์ฃผ๋ฉด ์ํ๋ ๊ฒฐ๊ณผ๋ฅผ ์ป์ ์ ์์
- Objective-C์ ๊ฒฝ์ฐ ๊ฐ๋ฅ
Array
- ๋์ผํ Type์ ๊ฐ์ ์ ์ฅํ ์ ์๋ Ordered List
- ๋์ผํ ๊ฐ์ด ๋ค๋ฅธ ์์น์์ ๋ฐ๋ณต์ ์ผ๋ก ๋ญ๋ก ์ ์์
- Foundation์ NSArray์ bridge
- ํํ
let array: Array<SomeType>()
let array: [SomeType]
let array = [Int]()
let array = Array<Int>()
- ์ ๊ทผ
array[0] = "A"
array[1..3] = ["a", "b", "c"]
Set
- ๋์ผํ type์ ๊ฐ์ ์ ์ฅํ ์ ์๋ Collection
- ๋์ผ ๊ฐ ์กด์ฌ ๋ถ๊ฐ
- Foundation์ NSSet๊ณผ bridge
- ํํ
let someSet: Set<Int>()
let genres: Set<String> = ["Rock", "Classic", "Hip hop"]
- type ๋ช
์๊ฐ ์๋ค๋ฉด array๋ก ์ ์ถ๋จ
- Element
- Element๋ Hashable type์ด์ด์ผ ํจ
- ๊ธฐ๋ณธ์ ์ธ type(String, int, Double, Bool)์ Hashable
- Custom type์ Set์์ ์ฌ์ฉํ๋ ค๋ฉด Hashable protocol ๋ง์กฑํด์ผํจ
- Hashable
public func hash(into hasher: inout Hasher)
- ์ด๋ค value์ hashValue๋ฅผ ์ ๊ณตํด์ value์ ๋์ผ์ฑ์ ๊ฒ์ถฉํ๋๋ฐ ์ฌ์ฉ
- value(struct)์ ๋ชจ๋ ๊ฐ์ ๋น๊ตํ๋ ๊ฒ๋ณด๋ค ๋น ๋ฆ
Dictionary
- key, value์ ์์ ์ ์ฅํ๋ collection
- key, value๋ ๊ฐ๊ฐ type์ด ์ง์ ๋์ด์ผ ํจ
- key๋ dictionary์์์ uniqueํ๋ฉฐ, value์ identifier๋ก ๋์
- key๋ hashable
- ์์ ์์ด ์ ์ฅํ๋ค.
- ํํ
let a: Dictionary<KeyType, ValueType>
let b: [KeyType: ValueType]
a = Dictionary<Int: String>()
b = [Int: String]()
var airports: [String, String] = ["XYZ": "Toronto", "DUB": "Dublin"]
var airports = ["XYZ": "Toronto", "DUB": "Dublin"]
- ๋ฉ์๋