tidwall / SwiftWebSocket

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

Warnings about deprecated function #112

Open moshegutman opened 6 years ago

moshegutman commented 6 years ago

I'm getting the following warning about substring(to: ) being deprecated.

'substring(to:)' is deprecated: Please use String slicing subscript with a 'partial range upto' operator.

It's inside the readResponse() function

if let r = line.range(of: ":") {
    key = trim(line.substring(to: r.lowerBound))
    value = trim(line.substring(from: r.upperBound))
}
moshegutman commented 6 years ago

I think the fix according to https://stackoverflow.com/questions/45562662/how-can-i-use-string-slicing-subscripts-in-swift-4 is:

if let r = line.range(of: ":") {
    key = trim(String(line[..<r.lowerBound]))
    value = trim(String(line[r.upperBound...]))
}
strikerEng commented 6 years ago

Wish I read this before I just submitted the same issue. Should I keep it open because it has not been fixed ?