SwiftWebSocket icon indicating copy to clipboard operation
SwiftWebSocket copied to clipboard

Swift 5.0 compile error.

Open starlight173 opened this issue 6 years ago • 9 comments

Fisrt of all thanks for great library.

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

Best

starlight173 avatar Mar 26 '19 04:03 starlight173

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 avatar Mar 26 '19 14:03 T2SoftDev

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

T2SoftDev avatar Mar 26 '19 14:03 T2SoftDev

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.

demofly avatar Mar 26 '19 22:03 demofly

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

starxor avatar Mar 27 '19 01:03 starxor

I just merged #138 which includes Swift 5.0 support.

tidwall avatar Apr 10 '19 01:04 tidwall

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

kylekurz avatar Jun 04 '19 20:06 kylekurz

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

nobre84 avatar Sep 23 '19 11:09 nobre84

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

wiistriker avatar Oct 28 '19 13:10 wiistriker

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

alexnivanov avatar May 19 '20 09:05 alexnivanov