In Swift, we can use the last
property of every string to get the last character of any character.
string.last!
This property returns a value that is the last character of a string.
Let’s look at the code below:
// create strings let name = "Theodore" let greetings = "Welcome to Edpresso!" // print last characters of strings. print(name.last!) print(greetings.last!)
last
property of the string class and get the last characters of the strings we created. And finally, we print the values to the console.RELATED TAGS
CONTRIBUTOR
View all Courses