Swift String reversed()

In this tutorial, we will learn about the Swift string reversed() method with the help of examples.

The reversed() method reverses the given string.


var msg = "Learn Swift"

// reverse msg var result = String(msg.reversed())
print(result) // Output: tfiwS nraeL

reversed() Syntax

The syntax of the string reversed() method is:


Here, string is an object of the String class.

reversed() Parameters

The reversed() method doesn't take any parameters.

reversed() Return Value

  • returns the reversed string.

Example: Swift string reversed()

var text = "Reverse Day "

// reverse text var result = String(text.reversed())
print(result) var numbers = "123"
// reverse numbers var result1 = String(numbers.reversed())


yaD esreveR

Using for Loop To Reverse String

In Swift, we can also use the for loop to reverse the given string. For example,

var text = "Reverse Day"
var result = ""

// loop through each character
for character in text {
 result = "\(character)" + result



yaD esreveR
Did you find this article helpful?