Tsallaka zuwa abun ciki
Justice Tech School

Swift Sets

A Set stores unique, unordered values with fast lookup. It supports union, intersection and subtracting.

Example
let a: Set = [1, 2, 3]
let b: Set = [3, 4]
print(a.union(b).sorted(), a.intersection(b), a.subtracting(b).sorted())
print(a.contains(2))

Exercise

Combine two sets.

a.(b)

Quiz Test

What does a Set guarantee?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.