WWDC 22 Embrace Swift generics 의 후속 조사
바로 인스턴스화할수 없는 타입
existential type
으로도 알려져 있음
In programming languages, an abstract type is a type in a nominative type system that cannot be instantiated directly; a type that is not abstract – which can be instantiated – is called a concrete type. Every instance of an abstract type is an instance of some concrete subtype. Abstract types are also known as existential types.[1]
In some languages, abstract types with no implementation (rather than an incomplete implementation) are known as *protocols …*
스위프트에서는 abstract type 을 static type 으로 사용할 때 existential type 이라고 가리키는 것 같다.
type(of:)
is constrained to a class or protocol, you can use that metatype to access initializers or other static members of the class or protocol.type(of:)
에 값을 전달하면 dynamic type 을 반환한다.protocol Test {
init()
func test()
}
struct SomeTest: Test {
func test() {}
static func testA() {}
}
var value: Test = SomeTest()
type(of:value).init() // dynamic type 을 반환한다는 점,
// Test.init() 이건 안됨 Test 는 existential type 으로 직접 인스턴스를 생성할 수 없음.
// type(of:value).testA() 이것도 안됨. Value of type 'Test.Type' has no member 'testA'