I'm new here and I'm glad for having initiated this course and grateful for Paul making it available for free. I've encountered a problem with the .reversed() function on arrays, which is that I don't know how to actually use them. Even if they are not really arrays anymore, I expected to be able to access any index of them as if they were. Otherwise, what's the point?
Maybe these articles will help.
To create a new item with reversed elements you actually need to specify the element type - which is how
Try the code in the
Thank you for your answers, these were helpful.
At least now I know that with type annotation
The thing that was causing confusion to me was this:
You can also see the same documentation in Xcode.
Try adding the following code to the end of the previous code in the Playground.
The results using
Strictly speaking, this also allocates memory, but it is released as soon as the print function is completed.
I think I know how to answer Lucas's question
The code that Paul typed only want to show this message: ReversedCollection<Array<String>>(_base: ["Bush", "Obama", "Trump", "Biden"]) in english: this is the reversed collection of string array that take from the base of "Bush" "Obama" "Trump" "Biden"
there is nothing useful about this because he only wanted to show you that message, how clever swift is.
He wanted to show that using reversed() can save a lot time and memory. Instead of you creating new array that going to take more memory, the new reversed array will take the original array and remember them and reverse them internally.
hope I don't disappoint you with my broken English answer.
SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.