Generics class with delegate protocol

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?

1 Like

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