Xcode Version 6.0 (6A279r): [Swift] Expand the collection protocol to return an index range
| Originator: | janoschhildebrand | ||
| Number: | rdar://17381669 | Date Originated: | 19-Jun-2014 |
| Status: | Duplicate of 17684975 (Open) | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode Version 6.0 (6A279r) |
| Classification: | Feature Request | Reproducible: | NA |
Summary:
The collection protocol in the Swift standard library defines properties 'startIndex' and 'endIndex'. These can be used to construct a range of the indices available in the collection as follows:
let collection: Collection
let range = collection.startIndex..collection.endIndex
It would be nice if the Collection protocol included a property as a shortcut that returns the available index range:
protocol Collection {
//...
var indexRange: Range<IndexType> { get }
}
let collection: Collection
let range = collection.indexRange
Currently is is very easy to iterate over a collections values by using the 'for in' syntax. This would enable the same succinct syntax for iterating over the indices without having to construct the index range manually each time:
for index in collection.indexRange {
}
Steps to Reproduce:
Expected Results:
Actual Results:
Version:
Xcode 6 - Beta 2 (6A216f)
Swift version 1.0 (swift-600.0.34.4.8)
OS X 10.10 (14A261i)
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!