A unique identifier for a class instance or metatype.
In Swift, only class instances and metatypes have unique identities. There is no notion of identity for structs, enums, functions, or tuples.
https://developer.apple.com/documentation/swift/objectidentifier
ObjectIdentifier is a class defined in the Swift Standard Library that is able to provide a unique identifier to reference types and metatypes.
https://medium.com/better-programming/understanding-swifts-objectidentifier-a62e85b2c9a1
使用ObjectIdentifier可以返回任意类型或者metatype(表示任意类型,包括class、struct、enum、protocol)的唯一标识。ObjectIdentifier 没有公开的属性和方法,但实际上遵循了Equatable
和Hashable
。
===
的比较判断,实际上就是比较的ObjectIdentifier。
某些场景可以作为dic[ObjectIdentifier:String]
的key,比较具有唯一性:
var a:[ObjectIdentifier:String]