Class中的ObjectIdentifier

ObjectIdentifier:用来判断类的标识,只要类实例、元类中才能使用。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Student {
}

let stuA = Student()
let stuB = stuA

// true
print(ObjectIdentifier(stuA) == ObjectIdentifier(stuB))
// true
print(stuA === stuB)


let stuC = Student()
// false
print(ObjectIdentifier(stuA) == ObjectIdentifier(stuC))
// false
print(stuA === stuC)