@@ -109,29 +109,31 @@ internal struct _ConcreteHashableBox<Base: Hashable>: _AnyHashableBox {
109
109
/// The `AnyHashable` type forwards equality comparisons and hashing operations
110
110
/// to an underlying hashable value, hiding the type of the wrapped value.
111
111
///
112
- /// For types that support conversions between each other using `as` or `as?`
113
- /// (such as `Int` and `NSNumber`), `AnyHashable` treats their values
114
- /// equivalently when type-erased by forwarding operations to canonical
115
- /// representations of the wrapped values.
112
+ /// Where conversion using `as` or `as?` is possible between two types (such as
113
+ /// `Int` and `NSNumber`), `AnyHashable` uses a canonical representation of the
114
+ /// type-erased value so that instances wrapping the same value of either type
115
+ /// compare as equal. For example, `AnyHashable(42)` compares as equal to
116
+ /// `AnyHashable(42 as NSNumber)`.
116
117
///
117
118
/// You can store mixed-type keys in dictionaries and other collections that
118
119
/// require `Hashable` conformance by wrapping mixed-type keys in
119
120
/// `AnyHashable` instances:
120
121
///
121
122
/// let descriptions: [AnyHashable: Any] = [
122
- /// AnyHashable(42) : "an Int",
123
- /// AnyHashable(Int8(43)) : "an Int8",
124
- /// AnyHashable(Set( ["a", "b"])) : "a set of strings"
123
+ /// 42 : "an Int",
124
+ /// 43 as Int8 : "an Int8",
125
+ /// ["a", "b"] as Set : "a set of strings"
125
126
/// ]
126
- /// print(descriptions[AnyHashable(42) ]!) // prints "an Int"
127
- /// print(descriptions[AnyHashable(Int8(42)) ]!) // prints "an Int"
128
- /// print(descriptions[AnyHashable(Int8(43)) ]!) // prints "an Int8"
129
- /// print(descriptions[AnyHashable(44)]) // prints "nil"
130
- /// print(descriptions[AnyHashable(Set( ["a", "b"])) ]!) // prints "a set of strings"
127
+ /// print(descriptions[42 ]!) // prints "an Int"
128
+ /// print(descriptions[42 as Int8 ]!) // prints "an Int"
129
+ /// print(descriptions[43 as Int8 ]!) // prints "an Int8"
130
+ /// print(descriptions[44]) // prints "nil"
131
+ /// print(descriptions[["a", "b"] as Set ]!) // prints "a set of strings"
131
132
///
132
- /// Note that `AnyHashable` instances are not guaranteed to preserve the hash
133
- /// encoding of their wrapped values, even in cases where hash values appear to
134
- /// match in a particular release of the standard library.
133
+ /// Note that `AnyHashable` does not guarantee that it preserves the hash
134
+ /// encoding of wrapped values. Do not rely on `AnyHashable` generating such
135
+ /// compatible hashes, as the hash encoding that it uses may change between any
136
+ /// two releases of the standard library.
135
137
@frozen
136
138
public struct AnyHashable {
137
139
internal var _box : _AnyHashableBox
@@ -198,13 +200,13 @@ public struct AnyHashable {
198
200
199
201
extension AnyHashable : Equatable {
200
202
/// Returns a Boolean value indicating whether two type-erased hashable
201
- /// instances wrap the same underlying value.
203
+ /// instances wrap the same value.
202
204
///
203
205
/// `AnyHashable` considers bridged counterparts (such as a `String` and an
204
- /// `NSString`) of the same value to be equivalent when type-erased. Where
205
- /// those compatible types have different definitions of equality comparisons,
206
- /// values that originally compare as not equal may then compare as equal when
207
- /// they are type-erased by conversion to `AnyHashable`:
206
+ /// `NSString`) of the same value to be equivalent when type-erased. If those
207
+ /// compatible types use different definitions for equality, values that were
208
+ /// originally distinct might compare as equal when they are converted to
209
+ /// `AnyHashable`:
208
210
///
209
211
/// let string1 = "café"
210
212
/// let string2 = "cafe\u{301}" // U+301 COMBINING ACUTE ACCENT
0 commit comments