Bird
0
0

Identify the error in this Swift code snippet:

medium📝 Debug Q6 of 15
iOS Swift - Swift Language Essentials
Identify the error in this Swift code snippet:
var set: Set = [1, 2, 3]
set.append(4)
AMissing type annotation for set
BSet does not have append method
CSet cannot contain integers
DSet must be immutable
Step-by-Step Solution
Solution:
  1. Step 1: Recall Set methods in Swift

    Set uses insert() to add elements, not append().
  2. Step 2: Identify method error

    append() is for arrays; calling it on Set causes error.
  3. Final Answer:

    Set does not have append method -> Option B
  4. Quick Check:

    Use insert() to add to Set [OK]
Quick Trick: Use insert() to add elements to Set [OK]
Common Mistakes:
  • Using append() on Set
  • Thinking Set can't hold Int
  • Confusing mutability rules

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes