SwiftWebSocket icon indicating copy to clipboard operation
SwiftWebSocket copied to clipboard

Warnings about deprecated function

Open moshegutman opened this issue 7 years ago • 2 comments

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 avatar Feb 22 '18 18:02 moshegutman

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...]))
}

moshegutman avatar Feb 22 '18 18:02 moshegutman

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

strikerEng avatar Jun 12 '18 20:06 strikerEng