Bird
0
0

Find the error in this Swift code:

medium📝 Debug Q7 of 15
iOS Swift - Swift Language Essentials
Find the error in this Swift code:
var count: Int
count = "five"
AMissing var keyword
BVariable count not initialized
CNo error, code runs fine
DType mismatch: cannot assign String to Int
Step-by-Step Solution
Solution:
  1. Step 1: Check variable type

    count is declared as an Int.
  2. Step 2: Check assigned value type

    Assigning a String "five" to an Int variable causes a type mismatch error.
  3. Final Answer:

    Type mismatch: cannot assign String to Int -> Option D
  4. Quick Check:

    Type mismatch error = C [OK]
Quick Trick: Variable type must match assigned value type [OK]
Common Mistakes:
  • Assigning wrong type to variable
  • Ignoring type declaration
  • Assuming implicit conversion

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes