• 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"]
  • ๋ฉ”์„œ๋“œ

    • updateValue
    • removeValue