Enumeration

  • ์—ฐ๊ด€๋œ Value๋“ค์˜ ๊ณตํ†ต Type์„ ์ •์˜ํ•  ๊ฒฝ์šฐ ์‚ฌ์šฉ

  • Type-Safeํ•œ ๋ฐฉ๋ฒ•์œผ๋กœ ์‚ฌ์šฉ ๊ฐ€๋Šฅ

  • ํŠน์ • ๊ฐ’์œผ๋กœ Raw Value ์ง€์ • ํ•„์ˆ˜ ์•„๋‹˜

  • Raw Value ์‚ฌ์šฉ ๊ฐ€๋Šฅ ์ž๋ฃŒ ๊ตฌ์กฐ

    • String
    • Chracter
    • Integer
    • Floating-point
  • ์‚ฌ์šฉ ๊ฐ€๋Šฅ ๊ธฐ๋Šฅ

    • Computed Property
    • Instance method
    • Initializer
    • Extension
    • Protocol
  • Raw Value์˜ ๋ฌต์‹œ์  ํ• ๋‹น

    enum Planet: Int {
        case mercury = 1, venus, earth, mars, jupiter, saturn, uranus, neptune // 2, 3, 4, 5, 6, 7, 8
    }
     
    enum CompassPoint: String { // RawValue type String์œผ๋กœ ์ง€์ •์‹œ 
        case north, south, east, west // member ์ด๋ฆ„์ด RawValue๊ฐ€ ๋จ
    }
  • Iterating

    • CaseIterable Protocol
  • Associated Values

    • member์— ์—ฐ๊ด€๋œ ๊ฐ’์„ ์ €์žฅํ•  ์ˆ˜ ์žˆ์Œ

    • ๊ฐ๊ฐ์˜ member์— ๋”ฐ๋ฅธ ๋‹ค๋ฅธ ํ˜•ํƒœ์˜ ๊ฐ’์„ ์ €์žฅํ•  ์ˆ˜ ์žˆ์Œ

      • tuple ์ง€์›์œผ๋กœ ์—ฌ๋Ÿฌ๊ฐœ ๊ฐ’๋„ ๊ฐ€๋Šฅ
    • Associated Value ์‚ฌ์šฉ์‹œ enum์— Raw Value type ์ง€์ • ๋ถˆ๊ฐ€

      enum Barcode {
          case upc(Int, Int, Int, Int)
          case qrCode(String)
      }
    • Optional๋„ Enum์ž„