Bird
0
0

Which of the following is the correct way to declare a Boolean variable named isActive with value true in Swift?

easy📝 Syntax Q3 of 15
iOS Swift - Swift Language Essentials
Which of the following is the correct way to declare a Boolean variable named isActive with value true in Swift?
Avar isActive: Bool = true
Blet isActive = 1
Cvar isActive: Int = 1
Dlet isActive = "true"
Step-by-Step Solution
Solution:
  1. Step 1: Understand Boolean declaration

    Boolean variables use Bool type and true/false values without quotes.
  2. Step 2: Check each option

    var isActive: Bool = true declares a Bool variable with true correctly.
  3. Final Answer:

    var isActive: Bool = true -> Option A
  4. Quick Check:

    Boolean declaration = var isActive: Bool = true [OK]
Quick Trick: Bool values are true or false without quotes [OK]
Common Mistakes:
  • Using quotes around true/false
  • Using Int instead of Bool
  • Using let with wrong type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes