swift determine if element is last 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: how to get last element of an array in swifg
let myArray = ["Hello!", "World!"]
let capacity = myArray.count
let lastElement = myArray[capacity-1]
print(lastElement)