Why swift protocol use func overloading instead on func with different names?

Viewed 618

Just started to learn swift and noticed that protocol UICollectionViewDelegate (https://developer.apple.com/documentation/uikit/uicollectionviewdelegate) has around 20 functions with the same name but different parameters. In C# we use overloads as well but we use them in case we want to do something similar like:

  • GetUser(int id)
  • GetUser(string userName)

but in swift we use the same func name for functions that do absolutely different things like:

  • func collectionView(UICollectionView, didSelectItemAt: IndexPath)
  • func collectionView(UICollectionView, targetContentOffsetForProposedContentOffset: CGPoint)

So the question is, why they don't use funcs like:

  • func didSelect(UICollectionView, ItemAt: IndexPath)
  • func targetContentOffsetForProposedContentOffset(UICollectionView, offset: CGPoint)

in this case func name actually tells us what it's going to do and it's easier to find function you need

If there is some documentation why such a decisions were made I would really appreciate it.

Thank you

2 Answers
Related