What does the "optional" keyword mean in a function declaration?

What does optional func myFunction() { .. } mean in the Apple API docs; for example this entry for UICollectionViewDelegate :

optional func collectionView(_ collectionView: UICollectionView,
didSelectItemAtIndexPath indexPath: NSIndexPath)

Upvotes: 1

Views: 232

Answers (1)

It means that classes adopting this protocol are not required to implement those methods in order to be conformant. Although not implementing any of these methods will not make for a good data source.

Upvotes: 3

Related Questions