tidwall / SwiftWebSocket

Fast Websockets in Swift for iOS and OSX
MIT License
1.53k stars 244 forks source link

Swift 5.0 compile error. #137

Open starlight173 opened 5 years ago

starlight173 commented 5 years ago

Fisrt of all thanks for great library.

Will there be a new version for xcode 10.2 and swift 5.0?

Best

T2SoftDev commented 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.

T2SoftDev commented 5 years ago

https://github.com/tidwall/SwiftWebSocket/pull/138 Thanks, @starxor

demofly commented 5 years ago

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.

starxor commented 5 years ago

Thanks, @demofly. hash(into:) is implemented by InnerWebSocket which is not an NSObject subclass, so all should work fine.

tidwall commented 5 years ago

I just merged #138 which includes Swift 5.0 support.

kylekurz commented 5 years ago

@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!

nobre84 commented 4 years ago

@tidwall would you push v2.8.0 to pod trunk please?

wiistriker commented 4 years ago

i just replace my dependency in Podfile with: pod 'SwiftWebSocket', :git => 'https://github.com/tidwall/SwiftWebSocket.git', :tag => 'v2.8.0'

alexnivanov commented 4 years ago

@wiistriker thx for the solution! Still waiting for it in the main trunk...