아미(아름다운미소)

[문법요약] 열거형(Enumeration) 본문

랭귀지/SWIFT

[문법요약] 열거형(Enumeration)

유키공 2017. 12. 14. 09:28
- 열거형(Enumeration)

import UIKit
// 열거형(Enumeration)
enum CompassPoint {
    case North
    case South
    case East
    case West
}

let point: CompassPoint = CompassPoint.North
let point2: CompassPoint = .East

switch point {
case .North:
    print("북쪽")
case .South:
    print("남쪽")
case .East:
    print("동쪽")
case .West:
    print("서쪽")
}

func printPoint(point: CompassPoint) {
    print(point)
}

printPoint(point: .South)

enum ErrorType: Int {
    case Success = 0,
    TypeError = 10,
    ValueError = 15,
    ParsingError
}

var errorType: ErrorType = .TypeError
print(errorType)

errorType = .ParsingError
print(errorType.rawValue)
Comments