What is the endIndex property of a string in Swift?
Overview
In Swift, the endIndex property is used to get a past-the-end position. This means that the position one is greater than the last valid subscript argument. If the string is empty, it returns startIndex.
Syntax
string.endIndex
Return value
This property returns the past-the-end position of a string.
Example
// print some strig endIndex property valuesprint("hello".endIndex)print("welcome".endIndex)print("to".endIndex)print("Edpresso!".endIndex)
Explanation
- Line 2–5: We use the
endIndexproperty on the strings and print the results to the console.