In Swift, String values have built-in methods to change their case:
s.uppercased() // converts all characters to uppercase
s.lowercased() // converts all characters to lowercase
Here are some examples:
let word = "Hello World"
let upper = word.uppercased() // "HELLO WORLD"
let lower = word.lowercased() // "hello world"
let name = "ALICE"
print(name.lowercased()) // "alice"
These methods return a new String — the original is not modified.
Assignment
Follow the Coding Tutorial and convert word to both uppercase and lowercase!
Hint
Use word.uppercased() and word.lowercased().
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check