Bird
0
0

What is the issue with this Swift code?

medium📝 Debug Q6 of 15
Swift - Variables and Constants
What is the issue with this Swift code?
var isAvailable: Bool = 1
AVariable should be declared with let, not var
BCannot assign an integer to a Bool type
CBool type requires explicit initialization with true or false only
DNo issue, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Check variable type and assigned value

    Variable isAvailable is declared as Bool but assigned integer 1.
  2. Step 2: Understand type compatibility

    Swift does not allow implicit conversion from Int to Bool.
  3. Final Answer:

    Cannot assign an integer to a Bool type -> Option B
  4. Quick Check:

    Bool must be true or false [OK]
Quick Trick: Bool only accepts true or false [OK]
Common Mistakes:
  • Using integers as Booleans
  • Confusing var and let for mutability
  • Assuming implicit type conversion

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes