# Generics class with delegate protocol

**URL:** <https://forums.swift.org/t/generics-class-with-delegate-protocol/12939>\
**Category:** Using Swift\
**Tags:** generics\
**Created:** [May 24, 2018, 1:51pm UTC](https://forums.swift.org/t/generics-class-with-delegate-protocol/12939 "2018-05-24T13:51:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bcse](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/bcse/32/3566_2.png) [@bcse](https://forums.swift.org/u/bcse)\
**Post date:** [May 24, 2018, 1:51pm UTC](https://forums.swift.org/t/generics-class-with-delegate-protocol/12939/1 "2018-05-24T13:51:48Z")

</div>

I am trying to make something works like UICollectionView, which let user implement UICollectionViewDelegate to handle actions. But since I am learning Swift, I would like to make it strong typed.

Here are my 2 attempts of designing the API. Both of them feels unnatural to use. It there a better way to do this?

> <https://gist.github.com/bcse/aa0063f05d9053bfd01783ec6dc12182>

---

<div class="post-metadata">

**Author:** ![jamieb](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@jamieb](https://forums.swift.org/u/jamieb)\
**Post date:** [May 25, 2018, 6:51am UTC](https://forums.swift.org/t/generics-class-with-delegate-protocol/12939/2 "2018-05-25T06:51:30Z")

</div>

Your third implementation is how most iOS developers, including me, would’ve done this. Casting is fine, and it’s definitely not strange.
