Documentation omission: -[UICollectionView indexPathsForVisibleItems] is not sorted

Originator:igeek1
Number:rdar://21008932 Date Originated:18-May-2015 07:24 PM
Status:Resolved Resolved:21-Jul-2016 01:53 PM
Product:iOS Product Version:8.3 (12F70)
Classification:Enhancement Reproducible:Always
 
Summary:
The array returned by -[UICollectionView indexPathsForVisibleItems] is not sorted, but the documentation does not mention this. Duplicate of, or related to, rdar://problem/13417031

Steps to Reproduce:
1. Call -[UICollectionView indexPathsForVisibleItems] in an app, expecting the results to be sorted, because the return type is ordered (NSArray instead of NSSet), and the documentation does not say anything about it not returning a sorted array.
2. Assume that the contents of the array you get back will be sorted.

Expected Results:
Your assumption that the array is sorted is correct, and your code works.

Actual Results:
Your assumption that the array is sorted is incorrect, and your code behaves strangely until you realize that the array is not sorted. 

Regression:
None

Notes:
I think I understand why this array returns an unsorted list: many uses of this API do not require a sorted list, so sorting it would just be a waste of cycles. However, it would be nice if it were documented that this method returns a not-necessarily-sorted collection of index paths. Alternatively, the method could return an NSSet, which does not suffer from implied sort order syndrome.

Comments

Message from Apple Developer Relations

This has been resolved.

Please verify here: https://developer.apple.com/reference/uikit/uicollectionview/1618020-indexpathsforvisibleitems?language=objc

We are now closing this bug report.

If you have questions or comments about the resolution, please update your bug report with that information so we can respond.


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!