#5: NSObject and Equatable
Question
// Swift Quiz
— objc.io (@objcio) March 22, 2019
class R: NSObject {
let int: Int
init(_ int: Int) { https://t.co/IvPXLb0pJS = int }
}
func ==(l: R, r: R) -> Bool { return https://t.co/LeFhy5dsm9 == https://t.co/LTLcrXtEsV }
let i1: NSObject = R(2)
let i2: NSObject = R(2)
i1 == i2
// What's the result?
Solution
Solution: False
— objc.io (@objcio) March 23, 2019
i1 and i2 are declared to be of type NSObject. However, the custom == operator is defined for R.
Therefore, i1 == i2 just performs pointer comparison.
https://t.co/s7500CWmAg