remove an element from the end of an array in swift

To remove an element from the end of an array in Swift, you can use the removeLast() method:

main.swift
var array = [1, 2, 3, 4, 5]
let removedElement = array.removeLast()
print(array) // [1, 2, 3, 4]
print(removedElement) // 5
124 chars
5 lines

The removeLast() method removes and returns the last element of the array. In the code above, we assign the removed element to a constant removedElement and then print the modified array and the removed element for demonstration purposes.

gistlibby LogSnag