Skip to content

Commit 2a60e2f

Browse files
committed
CGPoint, CGSize, CGRect, NSEdgeInsets: Modernize hashing
1 parent dd402b9 commit 2a60e2f

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

Diff for: Foundation/NSGeometry.swift

+19-13
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ extension CGPoint: NSSpecialValueCoding {
7474
return false
7575
}
7676
}
77-
78-
var hash: Int {
79-
return self.x.hashValue &+ self.y.hashValue
77+
78+
func hash(into hasher: inout Hasher) {
79+
hasher.combine(x)
80+
hasher.combine(y)
8081
}
8182

8283
var description: String {
@@ -166,9 +167,10 @@ extension CGSize: NSSpecialValueCoding {
166167
return false
167168
}
168169
}
169-
170-
var hash: Int {
171-
return self.width.hashValue &+ self.height.hashValue
170+
171+
func hash(into hasher: inout Hasher) {
172+
hasher.combine(width)
173+
hasher.combine(height)
172174
}
173175

174176
var description: String {
@@ -488,11 +490,12 @@ extension CGRect: NSSpecialValueCoding {
488490
return false
489491
}
490492
}
491-
492-
var hash: Int {
493-
return self.origin.hash &+ self.size.hash
493+
494+
func hash(into hasher: inout Hasher) {
495+
origin.hash(into: &hasher)
496+
size.hash(into: &hasher)
494497
}
495-
498+
496499
var description: String {
497500
return NSStringFromRect(self)
498501
}
@@ -588,9 +591,12 @@ extension NSEdgeInsets: NSSpecialValueCoding {
588591
return false
589592
}
590593
}
591-
592-
var hash: Int {
593-
return self.top.hashValue &+ self.left.hashValue &+ self.bottom.hashValue &+ self.right.hashValue
594+
595+
func hash(into hasher: inout Hasher) {
596+
hasher.combine(top)
597+
hasher.combine(left)
598+
hasher.combine(bottom)
599+
hasher.combine(right)
594600
}
595601

596602
var description: String {

0 commit comments

Comments
 (0)