Reputation: 15894
UICollectionView has a method indexPathsForVisibleItems that returns array of index paths. Where as UITableView has similar method indexPathsForVisibleRows that also returns array of index paths, buts its an optional. Why is there a difference between 2 similar methods from Apple itself?
Upvotes: 0
Views: 433
Reputation: 318774
Because Apple developers aren't perfect and they aren't always consistent.
UITableView
has been around since iOS 2.0 and someone decided back in 2008 to return nil
if there were no visible rows.
UICollectionView
was added years later in iOS 6.0 and someone decided to return an empty array instead of nil
if there were no visible rows.
Of course this was all in Objective-C. When Swift came along, it meant that UITableView indexPathsForVisibleRows
needed to be optional since the Objective-C property could be nil
.
BTW - In macOS, NSCollectionView indexPathsForVisibleItems
is a function instead of a property and it is a set, not an array. Again, inconsistent.
Upvotes: 1