How to get the first character from a string in Swift
In this tutorial, we are going to learn about how to get the first character from a string in Swift.
Getting the first character
To get the first character from a string, we can use the string.first
property in swift.
Example:
let name = "Polo"
if let firstCharacter = name.first {
print(firstCharacter)
}
Output:
"P"