Recall & Review
beginner
What is the difference between a
Character and a String in Swift?A Character represents a single letter, number, or symbol, while a String is a collection of Characters that form words or sentences.
Click to reveal answer
beginner
How do you declare a variable of type
Character in Swift?<p>You declare it by specifying the type <code>Character</code> and assigning a single character in double quotes, for example: <code>let letter: Character = "A"</code>.</p>Click to reveal answer
beginner
Can a Swift
String contain multiple characters including spaces and emojis?Yes, a String can hold multiple characters, spaces, emojis, and special symbols, like "Hello 👋".
Click to reveal answer
intermediate
How do you convert a
Character to a String in Swift?<p>You can convert a <code>Character</code> to a <code>String</code> by using the <code>String()</code> initializer, for example: <code>let str = String(character)</code>.</p>Click to reveal answer
intermediate
What happens if you try to assign multiple characters to a
Character variable in Swift?Swift will give a compile-time error because Character can only hold exactly one character.
Click to reveal answer
Which Swift type is used to store a single letter or symbol?
✗ Incorrect
Character holds a single letter or symbol, while String holds multiple characters.
How do you declare a string variable in Swift?
✗ Incorrect
Use String type and assign text in double quotes.
What will happen if you assign "AB" to a
Character variable?✗ Incorrect
Character must hold exactly one character, so multiple characters cause an error.
Which of these is a valid way to convert a
Character to a String?✗ Incorrect
Use the String() initializer to convert a Character to a String.
Can a Swift
String contain emojis?✗ Incorrect
String supports emojis and other Unicode characters.
Explain the difference between
Character and String types in Swift.Think about letters vs words.
You got /4 concepts.
Describe how to convert a
Character to a String and why you might need to do this.Consider when you want to join characters or print them as text.
You got /3 concepts.