let obj = Obj()
/// 方案一: 測試中 發(fā)現(xiàn)作用在<引用類型>的對(duì)象上能確保正確性
let point = Unmanaged<AnyObject>.passUnretained(obj as AnyObject).toOpaque()
let hashValue = point.hashValue // 這個(gè)就是唯一的掩蛤,可以作比較
/// 方案二:測試中 發(fā)現(xiàn)作用在<值類型>的對(duì)象上能確保正確性
let hashValue2 = withUnsafePointer(to: &obj) { (point) -> Int in
/// 閉包的實(shí)現(xiàn)有多種,可根據(jù)自己需求修改
return point.hashValue
}
/// 方案三:以唯一值來對(duì)應(yīng)地址的唯一(比如創(chuàng)建對(duì)象時(shí)陈肛,以時(shí)間做標(biāo)記等)