Open starlight173 opened 5 years ago
Code should be compilable & work at least after replacing
open override var hashValue: Int { return id }
with
open override var hash: Int { return id }
open override func isEqual(_ other: Any?) -> Bool {
guard let other = other as? WebSocket else { return false }
return self.id == other.id
}
in WebSocket class. Of course, the whole lib needs some refactoring to the latest Swift 5 changes.
https://github.com/tidwall/SwiftWebSocket/pull/138 Thanks, @starxor
https://forums.swift.org/t/xcode-10-gm-hash-into-issue-from-nsobject-class/16141/4
jrose Sep '18
Cocoa defines its own hashing API that is independent of Swift's Hashable. To customize hashing in NSObject subclasses, the correct property to override is NSObject.hash.
Trying to customize hashing by overriding hash(into:) and/or hashValue will not work correctly -- if you do that then NSDictionary, NSSet, and Foundation's other hashing collections won't work correctly with your class, often leading to severe problems.
It's rather unfortunate that hash and hashValue have distinct names; they are all too easy to confuse. In earlier Swift versions, NSObject.hashValue was accidentally left overridable, which added to the confusion.
Thanks, @demofly. hash(into:) is implemented by InnerWebSocket which is not an NSObject subclass, so all should work fine.
I just merged #138 which includes Swift 5.0 support.
@tidwall you merged that in and made a tag for v2.8.0, but never pushed that up to the cocoapod spec repo. Can you get that update pushed so we can pull directly from Cocoapods instead of needing to specify :git and :tag in our Podfiles (and that's impossible if consuming SwiftWebSocket as a dependency of another pod, as it will only pull from the official repo)?
Thanks!
@tidwall would you push v2.8.0 to pod trunk please?
i just replace my dependency in Podfile with: pod 'SwiftWebSocket', :git => 'https://github.com/tidwall/SwiftWebSocket.git', :tag => 'v2.8.0'
@wiistriker thx for the solution! Still waiting for it in the main trunk...
Fisrt of all thanks for great library.
Will there be a new version for xcode 10.2 and swift 5.0?
Best