2
final class Foo: NSObject, NSFileProviderItem
{
    public func hash(into hasher: inout Hasher)
    {
        hasher.combine(itemIdentifier)
    }
}

yields swift compiler errors:

Overriding non-open instance method outside of its defining module

Overriding declarations in extensions is not supported

Is there a way to fix NSObject hashability? I get duplicates of Foo instances in Sets which is precisely what I want to avoid.

Andrey Chernukha
  • 21,488
  • 17
  • 97
  • 161
Anton Tropashko
  • 5,486
  • 5
  • 41
  • 66

1 Answers1

4

Found the fix here:

https://forums.swift.org/t/xcode-10-gm-hash-into-issue-from-nsobject-class/16141/2

public override var hash: Int {
    var hasher = Hasher()
    hasher.combine(itemIdentifier)
    return hasher.finalize()
}

this seems to be a dup of NSObject subclass in Swift: hash vs hashValue, isEqual vs ==

Anton Tropashko
  • 5,486
  • 5
  • 41
  • 66