You are correct. Whether override `hashValue` is basing on the implementation of `==`. You can't do what you want. You should follow the required rules. However, if you don't want to get the unexpected result, you can always use a `convenience init(_ instance:Self)` in `extension` to convert subclass to superclass as I did in previous replies.
Zhaoxin On Sat, Sep 3, 2016 at 10:12 AM, Dmitri Gribenko <griboz...@gmail.com> wrote: > On Sat, Sep 3, 2016 at 4:47 AM, Zhao Xin via swift-users > <swift-users@swift.org> wrote: > > Hi Jordan, > > > > Both you and I were wrong. > > > > My wrongness: Your so called principle should be applied here. > > > > Your wrongness: If you really want a different hash value, the parent > > equality function has to be conservative and say that the different types > > are different. > > That's one way you can satisfy the rules, but not the only one. > > Think about class clusters. NSString has many subclasses that store > strings in different ways (for example, as Latin1 and UTF-16), but any > subclass instance compares equal to any other subclass instance that > carries the same character data, and also produces the same hash > value. > > Dmitri > > -- > main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if > (j){printf("%d\n",i);}}} /*Dmitri Gribenko <griboz...@gmail.com>*/ >
_______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users