# Dynamic dispatch in struct && protocol

**URL:** <https://forums.swift.org/t/dynamic-dispatch-in-struct-protocol/45161>\
**Category:** Using Swift\
**Tags:** dispatch\
**Created:** [February 28, 2021, 7:12am UTC](https://forums.swift.org/t/dynamic-dispatch-in-struct-protocol/45161 "2021-02-28T07:12:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zedd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/zedd/32/28092_2.png) [@Zedd](https://forums.swift.org/u/Zedd)\
**Post date:** [February 28, 2021, 7:12am UTC](https://forums.swift.org/t/dynamic-dispatch-in-struct-protocol/45161/1 "2021-02-28T07:12:33Z")

</div>

```
protocol Drawable {
    func draw()
}

struct Point: Drawable {
    func draw() {
        //
    }
}
struct Line: Drawable {
    func draw() {
        //
    }
}
let drawable: [Drawable]
drawable.forEach { $0.draw() }

```

in this case, Is there a dynamic dispatch? even if struct?

---

<div class="post-metadata">

**Author:** ![Lantua](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lantua/32/8868_2.png) [@Lantua](https://forums.swift.org/u/Lantua)\
**Post date:** [February 28, 2021, 1:03pm UTC](https://forums.swift.org/t/dynamic-dispatch-in-struct-protocol/45161/3 "2021-02-28T13:03:59Z")

</div>

In particular, _all_ and _only_ protocol requirements and class members use dynamic dispatch (there's also Obj-C message-sending system, but heck).

Now, there is one caveat due to how Swift compiles generics: all generics use the same function for protocol requirement.

Let's say, you add another generic shape.

```swift
struct X<Value> { ... }

```

All instances of `X`, regardless of the type of `Value`, will use the same function when referring to `Drawable.draw`.
