Inefficient Membership Test (ARCH9075)
Key swift.performance.inefficient-membership-test · Severity warning · Category performance
Flags array.contains inside a loop - an O(n) scan per iteration; a Set makes it O(1).
Incorrect
Section titled “Incorrect”for id in ids { if blockedList.contains(id) { skip(id) }}Correct
Section titled “Correct”let blocked = Set(blockedList)for id in ids where blocked.contains(id) { skip(id) }Convert the collection to a Set once, outside the loop.