If you want to remove the last character from a Swift string then you can do it easily using the
removeLast() or the
Both of the methods are able to perform the task. But there is a difference.
removeLast() method is mutable. So it will modify the original string.
On the other hand, the
dropLast() method is immutable. That means it will not modify the original string, but it will create a new string with the last character removed.
Now let’s see an example of removing the last character from the string using the
var myName = "Abraham" myName.removeLast() print(myName)
In the above example, the string
myName has been modified because we have used the
Now let’s do this thing using the
var myName = "Abraham" var removedLast = myName.dropLast() print(removedLast)
This time we have got a new array because we have used the