[swift] 55. 자료형 체크

RudinP·2023년 10월 20일
0

Study

목록 보기
74/227
  1. if+is
if myCat is Cat{
	...
}
  1. func+guard+is
func isCat{
	//Cat이 아닌 경우
	guard myCat is Cat else{
    	...
        return
    }
    //Cat인 경우
    ...
}
  1. switch + is
switch myCat{
	case is Dog:
    	...
    case let myKitty as Cat:
    	...
}
  1. if + case + is
//자료형이 앞에 옴 주의
if case is Cat = myCat{
	...
}
  1. func + guard + case + is
func isMyCat{
	guard case is Cat = myCat else{
    	...
        return
    }
    ...
}
profile
곰을 좋아합니다. <a href = "https://github.com/RudinP">github</a>

0개의 댓글