Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Swift 5.0 compile error. #137

Open
starlight173 opened this issue Mar 26, 2019 · 9 comments
Open

Swift 5.0 compile error. #137

starlight173 opened this issue Mar 26, 2019 · 9 comments

Comments

@starlight173
Copy link

starlight173 commented Mar 26, 2019

Fisrt of all thanks for great library.

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

Best

@T2SoftDev
Copy link

T2SoftDev commented Mar 26, 2019

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
Copy link

#138
Thanks, @starxor

@demofly
Copy link

demofly commented Mar 26, 2019

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
Copy link

starxor commented Mar 27, 2019

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

@tidwall
Copy link
Owner

tidwall commented Apr 10, 2019

I just merged #138 which includes Swift 5.0 support.

@kylekurz
Copy link

kylekurz commented Jun 4, 2019

@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
Copy link

nobre84 commented Sep 23, 2019

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

@wiistriker
Copy link

wiistriker commented Oct 28, 2019

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

@alexnivanov
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants