Challenge - 5 Problems
Swift Character Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Swift code?
Consider the following Swift code snippet. What will it print?
Swift
let greeting: String = "Hello, 👋" print(greeting.count)
Attempts:
2 left
💡 Hint
Remember that some emoji count as a single character in Swift strings.
✗ Incorrect
The string "Hello, 👋" contains 7 visible characters plus the emoji 👋 which counts as one character, making the total count 8.
❓ Predict Output
intermediate2:00remaining
What is the output of this Swift code using Character type?
What will this Swift code print?
Swift
let letter: Character = "A" print(letter.isLetter)
Attempts:
2 left
💡 Hint
Check if the Character type has a property to check if it is a letter.
✗ Incorrect
The Character type in Swift has the property isLetter which returns true if the character is a letter.
❓ Predict Output
advanced2:00remaining
What is the output of this Swift code with Unicode scalars?
What will this Swift code print?
Swift
let heart = "\u{2764}\u{FE0F}" print(heart.count)
Attempts:
2 left
💡 Hint
Unicode scalars can combine to form a single character.
✗ Incorrect
The two Unicode scalars combine to form a single emoji character, so the count is 1.
❓ Predict Output
advanced2:00remaining
What is the output of this Swift code using string interpolation with characters?
What will this Swift code print?
Swift
let char1: Character = "S" let char2: Character = "w" let char3: Character = "i" let char4: Character = "f" let char5: Character = "t" let word = "\(char1)\(char2)\(char3)\(char4)\(char5)" print(word)
Attempts:
2 left
💡 Hint
String interpolation joins characters into a string without spaces.
✗ Incorrect
String interpolation concatenates the characters into the string "Swift" without spaces.
🧠 Conceptual
expert3:00remaining
How many characters are in this Swift string?
Consider the Swift string
let s = "e\u{301}". How many characters does s.count return?Attempts:
2 left
💡 Hint
Unicode combining marks combine with base characters to form one character.
✗ Incorrect
The string contains the letter 'e' plus a combining acute accent. Swift counts this as one character.