-
[Swift] Any 와 AnyObjectiOS/🟠 Swift 2021. 10. 16. 10:49
1차 수정: 21.10.17 안녕하세요🐶 이번 시간에는 Any 와 AnyObject 를 정리해보았습니다. 구체적인 타입이 아닌 아무 타입 으로 작업하기 위해 스위프트가 제공하는 두 가지 특별한 타입 Any 타입 변수에 넣어주는 것이 타입 컨버전이 아닌 타입 캐스팅임에 유의하자. Any 와 AnyObject 타입은 생성자를 제공하지 않는다. 아래는 캐스팅의 특징 👇🏻👇🏻👇🏻👇🏻 Casting doesn’t actually modify the instance or change its values. The underlying instance remains the same; it’s simply treated and accessed as an instance of the type to which it has b..
-
Checking Type & Downcasting - Type CastingiOS/🟠 Swift 2021. 1. 21. 00:57
Checking Type /* item 이 Transportation 타입으로 Upcasting 되어 있는 상황 */ ... if item is Metro { } else if item is Bus { } ... Type check operator ` is ` 를 사용하여 인스턴스가 특정 subclass 타입인지 아닌지 확인합니다. 인스턴스가 특정 subclass 타입이 맞다면 true 를 , 아니라면 false 를 반환합니다. Type Casting 은 타입을 다른 타입으로 아예 바꾸는 것이 아니라 다른 타입으로 취급만 하는 것이므로, is 연산자로 sublcass인지 아닌지를 확인 할 수 있겠습니다. Downcasting # as? # as! 어떤 수퍼 클래스 타입을 가진 인스턴스는 사실 서브클래스 ..