Bird
0
0

Identify the error in this Swift code snippet:

medium📝 Debug Q14 of 15
iOS Swift - Swift Language Essentials
Identify the error in this Swift code snippet:
var isActive: Bool = "true"
print(isActive)
Aprint() cannot print Bool values
BBool cannot be assigned a String value
CVariable name is invalid
DMissing semicolon at end of line
Step-by-Step Solution
Solution:
  1. Step 1: Analyze variable assignment

    isActive is declared as Bool but assigned the string "true" (in quotes), which is incorrect.
  2. Step 2: Understand type mismatch

    Bool must be assigned true or false without quotes. Assigning a String causes a type error.
  3. Final Answer:

    Bool cannot be assigned a String value -> Option B
  4. Quick Check:

    Bool = true/false only, no quotes [OK]
Quick Trick: Bool values are true or false without quotes [OK]
Common Mistakes:
  • Using quotes around true/false
  • Expecting semicolon error
  • Thinking print can't show Bool

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes