tera
1
How is this magic done? Could I achieve the same 1...4 behaviour with my foo & bar methods of my P protocol, or is this special trick baked into the compiler?
-
I can implement just hash(into:), in this case calling hashValue calls my hash(into:).
-
I can implement just hashValue, in this case calling hash(into:) calls my hashValue.
-
if I do #2 I am getting a warning: 'Hashable.hashValue' is deprecated as a protocol requirement; conform type 'C' to 'Hashable' by implementing 'hash(into:)' instead.
-
I can implement both hash(into:) and hashValue, in this case calling each calls the corresponding methods.
xwu
(Xiaodi Wu)
2
It is baked into the compiler. See, for example:
2 Likes