== vs === — what's the difference?
The idea
==compares values. Defined by theEquatableprotocol; for your own types you decide what "equal" means (all fields, onlyid, case-insensitive).===compares identity: whether two references point to the same object in memory. Defined only forAnyObject, i.e. classes (and class-bound protocols). For structs, enums and tuples===does not exist.
final class Node: Equatable {
let value: Int
init(_ value: Int) { self.value = value }
static func == (l: Node, r: Node) -> Bool { l.value == r.value }
}
let a = Node(1), b = Node(1), c = a
print(a == b, a === b, a === c) // true false true
The rest of this answer, with code and interview follow-ups, is in the DevPrep app.
Read the full answer in DevPrep