Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
How to reverse an integer array in swift
integer array
eg: var ab = [1,2,3,4]
var ab = [1,2,3,4]
I want to store the array in reverse format.
The result should be
ab = [4,3,2,1]
use ab.reversed() function which returns a reversed array.
Add a comment
var ab = [1, 2, 3, 4] func reverse(_ arr: [Int]) -> [Int] { return arr.reversed() // we return here } print(reverse(ab)) // The answer print as you need! [4, 3, 2, 1]
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.