Set operations in swift

Welcome, Dee. I’m just learning Swift myself also.
Another way of saying “common to both a and b” would be “the intersection of a and b”, and another way of saying “if not all of the values of set a are contained in set b” would be “if set a is not a subset of set b”.

let a: Set = [1, 2, 3]
let b: Set = [3, 5, 2]
if !a.isSubset(of: b) {
    let c: Set = a.intersection(b)
}

Leave a Comment