[swift] 72. switch 에서 tuple 사용

RudinP·2023년 10월 26일
0

Study

목록 보기
99/227

switch 에서 tuple 사용

  • if case 도 가능
let somePoint = (x: 0, y: 1)

switch somePoint{
case (x:0, y:0):
	print("중심")
case (_, y:0):
	print("x축에 있음")
case (x:0, _):
	print("y축에 있음")
case (-2...2, -2...2):
	print("상자 안에 있다")
default:
	print("\(somePoint.x), \(somePoint.y)에 있음")
}

if case(x: 2, y: 2) = somePoint{
	...
}

func check(){
	guard case (x: 2, y: 2) = somePoint else{
    	 return
    }
    ...
}
profile
곰을 좋아합니다. <a href = "https://github.com/RudinP">github</a>

0개의 댓글