The reversed() method reverses the given string.
Example
reversed() Syntax
The syntax of the string reversed() method is:
String(string.reversed()
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()
Output
yaD esreveR 321
Using for Loop To Reverse String
In Swift, we can also use the for loop to reverse the given string. For example,
Output
yaD esreveR