https://developer.apple.com/documentation/swift/type(of:)#Finding-the-Dynamic-Type-in-a-Generic-Context

전달된 값의 dynamic type 을 반환한다.

<aside> ⌨️ Index

</aside>

Discussion


static type

dynamic type

concrete type

existential type

예시 코드

class A {}
class B: A{}

func printValue(_ value: A) {
    let t = type(of: value)
    print("\\(t)")
}

let b: A = B()

printValue(b)

// prints "B"

Finding the Dynamic Type in a Generic Context


특정 상황에서는 예상 하지 못한 결과가 나올 수도 있다.

let stringAsP: P = "Hello!"