나의 발자취

Switch Statement: Where clause 본문

앱 개발/iOS

Switch Statement: Where clause

달모드 2023. 6. 20. 01:37
var randomNumber = Int.random(in: 0...10)
 
switch randomNumber {
  case let x where x % 2 == 0:
    print("\(randomNumber) is even")
  case let x where x % 2 == 1:
    print("\(randomNumber) is odd")
  default:
    print("Invalid")
}

case에서 임시변수 x를 선언 후 where 문으로 조건 설정 가능(람다같이)

 

 

 

 

Comments