init(_:)
Creates an instance that uniquely identifies the given class instance.
Declaration
init(_ x: AnyObject)Parameters
- x:
An instance of a class.
Discussion
The following example creates an example class IntegerRef and compares instances of the class using their object identifiers and the identical-to operator (===):
class IntegerRef {
let value: Int
init(_ value: Int) {
self.value = value
}
}
let x = IntegerRef(10)
let y = x
print(ObjectIdentifier(x) == ObjectIdentifier(y))
// Prints "true"
print(x === y)
// Prints "true"
let z = IntegerRef(10)
print(ObjectIdentifier(x) == ObjectIdentifier(z))
// Prints "false"
print(x === z)
// Prints "false"