@@ -195,25 +195,56 @@ public var NO: ObjCBool {
195
195
//===----------------------------------------------------------------------===//
196
196
197
197
// NSObject implements Equatable's == as -[NSObject isEqual:]
198
- // NSObject implements Hashable's hashValue() as -[NSObject hash]
198
+ // NSObject implements Hashable's hashValue as -[NSObject hash]
199
199
// FIXME: what about NSObjectProtocol?
200
200
201
201
extension NSObject : Equatable , Hashable {
202
+ /// Returns a Boolean value indicating whether two values are
203
+ /// equal. `NSObject` implements this by calling `lhs.isEqual(rhs)`.
204
+ ///
205
+ /// Subclasses of `NSObject` can customize Equatable conformance by overriding
206
+ /// `isEqual(_:)`. If two objects are equal, they must have the same hash
207
+ /// value, so if you override `isEqual(_:)`, make sure you also override the
208
+ /// `hash` property.
209
+ ///
210
+ /// - Parameters:
211
+ /// - lhs: A value to compare.
212
+ /// - rhs: Another value to compare.
202
213
public static func == ( lhs: NSObject , rhs: NSObject ) -> Bool {
203
214
return lhs. isEqual ( rhs)
204
215
}
205
216
206
217
/// The hash value.
207
218
///
219
+ /// `NSObject` implements this by returning `self.hash`. Subclasses can
220
+ /// customize hashing by overriding the `hash` property.
221
+ ///
208
222
/// **Axiom:** `x == y` implies `x.hashValue == y.hashValue`
209
223
///
210
224
/// - Note: the hash value is not guaranteed to be stable across
211
225
/// different invocations of the same program. Do not persist the
212
226
/// hash value across program runs.
213
- @objc
214
- open var hashValue : Int {
227
+ @objc open // FIXME: Should be @nonobjc public. rdar://problem/42623458
228
+ var hashValue : Int {
215
229
return hash
216
230
}
231
+
232
+ /// Hashes the essential components of this value by feeding them into the
233
+ /// given hasher.
234
+ ///
235
+ /// NSObject implements this by feeding `self.hash` to the hasher. Subclasses
236
+ /// can customize hashing by overriding the `hash` property.
237
+ public func hash( into hasher: inout Hasher ) {
238
+ // FIXME: We should combine self.hash here, but hashValue is currently
239
+ // overridable.
240
+ hasher. combine ( hashValue)
241
+ }
242
+
243
+ public func _rawHashValue( seed: ( UInt64 , UInt64 ) ) -> Int {
244
+ // FIXME: We should use self.hash here, but hashValue is currently
245
+ // overridable.
246
+ return self . hashValue. _rawHashValue ( seed: seed)
247
+ }
217
248
}
218
249
219
250
extension NSObject : CVarArg {
0 commit comments