Core Graphics: CGRect, etc. not Hashable

I'm curious if there's a reason CGRect, CGPoint, CGVector, and CGSize are not Hashable?


Writing an extension was easy enough, it just seems odd, and I couldn't find any discussion about it anywhere.

Accepted Answer

AFAIK, t-uples are not dirctly hashable.


For instance, (Int, Int) is not hashable, but can also get an extension to make it hashable.


I found on SO this elegant way to make anything hashable, here for CGRect


extension CGRect: Hashable {
    public var hashValue: Int {
        return NSCoder.string(for: self).hashValue
    }
}
Core Graphics: CGRect, etc. not Hashable
 
 
Q