Complete the code to check if two class instances refer to the same object.
if object1 [1] object2 { print("Same instance") }
In Swift, the identity operator to check if two references point to the same instance is ===.
Complete the code to check if two class instances do NOT refer to the same object.
if objectA [1] objectB { print("Different instances") }
The operator !== checks if two references do not point to the same instance.
Fix the error in the code to correctly check identity between two instances.
if person1 [1] person2 { print("They are the same person") }
Use === to check if two class instances are the same object in memory.
Fill both blanks to create a condition that prints "Same" if two objects are identical and "Different" if not.
if obj1 [1] obj2 { print("Same") } else if obj1 [2] obj2 { print("Different") }
The first blank uses === to check identity, the second uses !== to check non-identity.
Fill both blanks to create a function that returns true if two references are identical and false otherwise.
func areIdentical(_ a: AnyObject, _ b: AnyObject) -> Bool {
return a [1] b [2] true : false
}The function uses the identity operator === and the ternary operator ? : to return true if identical, else false.