Bird
0
0

Identify the error in this Swift code snippet targeting premium users:

medium📝 Debug Q14 of 15
iOS Swift - iOS Basics and Setup
Identify the error in this Swift code snippet targeting premium users:
func greetUser(isPremium: Bool) {
  if isPremium = true {
    print("Thanks for being premium!")
  } else {
    print("Welcome!")
  }
}
AMissing return type in function
BIncorrect print statement syntax
CUsing '=' instead of '==' in the if condition
DFunction name should be capitalized
Step-by-Step Solution
Solution:
  1. Step 1: Check the if condition syntax

    The condition uses '=' which is assignment, not comparison. It should be '==' to compare values.
  2. Step 2: Verify other syntax elements

    Function return type is optional for Void, print syntax is correct, and function naming conventions allow lowercase.
  3. Final Answer:

    Using '=' instead of '==' in the if condition -> Option C
  4. Quick Check:

    Comparison needs '==' not '=' [OK]
Quick Trick: Use '==' for comparison, '=' is assignment [OK]
Common Mistakes:
  • Confusing assignment '=' with comparison '=='
  • Thinking function must declare return type
  • Assuming print syntax is wrong

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes