-[UICollectionView cellForItemAtIndexPath:] should return a "__kindof UICollectionViewCell *"

Originator:guillaume.algis
Number:rdar://35668509 Date Originated:22-nov.-2017 06:36 PM
Status:Open Resolved:
Product:iOS + SDK Product Version:iOS 10+
Classification:Enhancement Reproducible:Always
 
Summary:
There is very little chance that cellForItemAtIndexPath: will actually return an instance of UICollectionViewCell, as for most uses cases one will subclass it to customize the UI.
So right now, we need to cast the return value of this method everywhere it's used. Using "__kindof" would remove the need to add theses cast.

-[UICollectionView collectionView:cellForItemAtIndexPath:] aleady uses the __kindof annotation, as is -[UITableView cellForRowAtIndexPath:].

Steps to Reproduce:
1. Register a custom subclass of UICollectionViewCell to be used in a UICollectionView
2. Use the method cellForItemAtIndexPath: to retrieve a cell, and store it in a variable of your subclass' type

 Eg . MyCellSubclass *cell = [myCollectionView cellForItemAtIndexPath:indexPath];

Expected Results:
No compiler error is produced

Actual Results:
The compiler produces the error "Incompatible pointer types initializing 'MyCellSubclass *' with an expression of type 'UICollectionViewCell * _Nullable'" 

Version:
iOS 10+

Notes:

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!