Swift - Enumeration 사용

신동준·2022년 4월 25일
0

enum Series

목록 보기
1/7

“Enum” is short for “enumeration”, and it’s a way of letting you use fixed names for special values rather than relying on strings or integers.

라고 hackingwithSwift 나와있지만 내가 이해하는 enum은 switch을 강제할수있는거같다

Direction(North, South, East, West)처럼 그 값이 상식적으로 바뀌지않을거 같을떄 사용한다

example

enum IpadSeries {
	case Basic
    case Air
    case Pro
}
struct Device {
	var price: Double
    var deviceType: IpadSeries
}
let somedevie = Device(price:1000.123, .Pro)
   

객체를 생성할떄 deviceType String해놓는거보다 훨씬 좋아보인다!!

profile
Swift 예비개발자

0개의 댓글