Now that I've learned Swift (to a reasonable level) I'm trying to get to grips with the standard library, but in truth it's mainly ελληνικά to me!
So a specific question: I have an array of strings and I can call reverse() on it.
let arr = ["Mykonos", "Rhodes", "Naxos"].reverse()
Now naively I thought I'd get back a type of Array from this. (Ruby for example has a similar method that you pass an array and get back an array)
But arr is now actually of type
ReverseRandomAccessCollection<Array<String>>
which is actually a struct, which conforms to CollectionType:
public struct ReverseRandomAccessCollection<Base : CollectionType where Base.Index : RandomAccessIndexType> : _ReverseCollectionType
This means I can do this:
for item in arr {
print(item)
}
but I can't do
print(arr[0])
Why is this designed to be this way?
Dictionaries in Swift also implement CollectionType, so I can do this:
let dict = ["greek" : "swift sometimes", "notgreek" : "ruby for this example"].reverse()
But dictionaries are not ordered like arrays, so why can I call reverse() on dicts?
Bonus points if anyone can point me in the direction of where I can read up and improve my Swift stdlib foo, Ευχαριστώ!