Swift/문법
[SWIFT]swich case 구간 설정
삽질중
2023. 7. 5. 10:52
switch case문의 구간 값을 설정하는 방법 이다. 간단한 예제로 레벨별 Section 등급을 가져오는 예제
level이 0...9 이면 Section 등급은 0 이고 level이 10...19 이면 Section 등급은 1
enum LevelSection: Int {
case Section0 = 0
case Section1
case Section2
case Section3
case Section4
case Section5
case Section6
case Section7
case Section8
case Section9
case Section10
}
func getLevelSection(level: Int) -> LevelSection {
switch level {
case 0...9:
return LevelSection.Section0
case 10...19:
return LevelSection.Section1
case 20...29:
return LevelSection.Section2
case 30...39:
return LevelSection.Section3
case 40...49:
return LevelSection.Section4
case 50...59:
return LevelSection.Section5
case 60...69:
return LevelSection.Section6
case 70...79:
return LevelSection.Section7
case 80...89:
return LevelSection.Section8
case 90...Int.max:
return LevelSection.Section9
default:
return UserLevelSection.Section0
}
}