Timur Cheberda
1 min readJul 30, 2022

--

Hi there and thank you for your question :)

Class-bound protocols really stand apart and differ from others

protocols. When we talk about protocol presentation, we always mean

existential container. The existential container itself is created only at runtime and only at moment of use. One container per value. Here you need to understand that

the existential container consists in particular of two things, the

existential container (after all, it also needs to allocate memory) and the

the value that is stored inside this container.

The existential container itself can be a value-type and such a container

is always stored on the stack (unlike other value-types). So the construction:

`protocol Car: AnyObject` {

func drive()

}

class BMW: Car {

func drive() {}

}

func justDrive() {

let bmw = BWM()

let sample: Car = bmw

sample.drive()

}

As it turned out, now the existential container itself is already allocated on the heap.

Accordingly, the semantics of its use becomes Reference.

--

--

No responses yet