How to reverse array in Swift without using “.reverse()”?

后端 未结 21 1803
清歌不尽
清歌不尽 2020-12-08 20:14

I have array and need to reverse it without Array.reverse method, only with a for loop.

var names:[String] = [\"Apple\", \"Microsof         


        
21条回答
  •  半阙折子戏
    2020-12-08 20:57

    Here the code for swift 3

    let array = ["IOS A", "IOS B", "IOS C"]
        for item in array.reversed() {
        print("Found \(item)")
        }
    

提交回复
热议问题