0
0
Swiftprogramming~20 mins

Character and String types in Swift - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Swift Character Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
A7
B8
C9
D6
Attempts:
2 left
💡 Hint
Remember that some emoji count as a single character in Swift strings.
Predict Output
intermediate
2: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)
Anil
Bfalse
CCompilation error
Dtrue
Attempts:
2 left
💡 Hint
Check if the Character type has a property to check if it is a letter.
Predict Output
advanced
2: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)
A1
B2
C3
D0
Attempts:
2 left
💡 Hint
Unicode scalars can combine to form a single character.
Predict Output
advanced
2: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)
AS w i f t
B[S, w, i, f, t]
CSwift
DCompilation error
Attempts:
2 left
💡 Hint
String interpolation joins characters into a string without spaces.
🧠 Conceptual
expert
3: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?
A1
B2
C0
DCompilation error
Attempts:
2 left
💡 Hint
Unicode combining marks combine with base characters to form one character.