What is the way of extracting last word in a String in Swift? So if I have \"Lorem ipsum dolor sit amet\", return \"amet\". What is the most efficient way of doing this?
First use componentsSeparatedByString to split your string into an array by space, then get the last word of the array using .last
componentsSeparatedByString
.last
var string = "Lorem ipsum dolor sit amet" var stringArr = string.componentsSeparatedByString(" ") var lastWord = stringArr.last //amet