Bird
0
0

Identify the error in this Swift code snippet:

medium📝 Debug Q6 of 15
Swift - Collections
Identify the error in this Swift code snippet:
let set1: Set = [1, 2, 3]
let set2: Set = [2, 3, 4]
let result = set1.intersect(set2)
print(result)
ASets must be arrays to use intersection
BSets cannot be compared using intersection
CMethod intersect() does not exist; should use intersection()
DMissing parentheses in print statement
Step-by-Step Solution
Solution:
  1. Step 1: Check method name for intersection

    Swift's correct method is intersection(), not intersect().
  2. Step 2: Confirm other code parts are correct

    Sets can use intersection, and print syntax is correct.
  3. Final Answer:

    Method intersect() does not exist; should use intersection() -> Option C
  4. Quick Check:

    Use intersection() method name [OK]
Quick Trick: Use exact method names: intersection(), not intersect() [OK]
Common Mistakes:
  • Typing method names incorrectly
  • Assuming sets can't use intersection
  • Thinking print syntax is wrong

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes