get last element from for each in swift code example
Example 1: check enumatted arrray last item swift
for (idx, element) in array.enumerated() {
if idx == array.endIndex-1 {
// handling the last element
}
}
Example 2: get last element of array swift
let array = ["A", "B", "C", 1, 2, 3]
let size = array.count
last_element = array[size-1]
print(last_element)