pusher / NWWebSocket

A WebSocket client written in Swift, using the Network framework from Apple.
MIT License
123 stars 25 forks source link

Errors finding types in Xcode #30

Closed finleyowen closed 3 years ago

finleyowen commented 3 years ago

Hi, I am trying to create a NWWebSocket, and I've pasted the following code from the documentation:

import Foundation
import NWWebSocket

class MyClientManager {

}

extension MyClientManager: WebSocketConnectionDelegate {

    func webSocketDidConnect(connection: WebSocketConnection) {
        // Respond to a WebSocket connection event
    }

    func webSocketDidDisconnect(connection: WebSocketConnection,
                                closeCode: NWProtocolWebSocket.CloseCode, reason: Data?) {
        // Respond to a WebSocket disconnection event
    }

    func webSocketViabilityDidChange(connection: WebSocketConnection, isViable: Bool) {
        // Respond to a WebSocket connection viability change event
    }

    func webSocketDidAttemptBetterPathMigration(result: Result<WebSocketConnection, NWError>) {
        // Respond to when a WebSocket connection migrates to a better network path
        // (e.g. A device moves from a cellular connection to a Wi-Fi connection)
    }

    func webSocketDidReceiveError(connection: WebSocketConnection, error: NWError) {
        // Respond to a WebSocket error event
    }

    func webSocketDidReceivePong(connection: WebSocketConnection) {
        // Respond to a WebSocket connection receiving a Pong from the peer
    }

    func webSocketDidReceiveMessage(connection: WebSocketConnection, string: String) {
        // Respond to a WebSocket connection receiving a `String` message
    }

    func webSocketDidReceiveMessage(connection: WebSocketConnection, data: Data) {
        // Respond to a WebSocket connection receiving a binary `Data` message
    }
}

Xcode is giving me the error: Cannot find type 'NWError' in scope and the same error for NWProtocolWebSocket.
Am I doing something wrong? Any help appreciated.
Thanks

danielrbrowne commented 3 years ago

@finleyowen What platform are you targeting, and what OS version?

finleyowen commented 3 years ago

@finleyowen What platform are you targeting, and what OS version?

iOS 14.0

danielrbrowne commented 3 years ago

@finleyowen Ah, I've found the issue - you need to also import Network (as well as import NWWebSocket).

I will either update the README to reflect this, or make it so importing Apple's Network framework isn't necessary in a future release. Please let me know if that solves your issue.

finleyowen commented 3 years ago

@danielrbrowne yep, that worked. Thank you! Would you like me to close this issue, or leave it open for others with the same question?

danielrbrowne commented 3 years ago

I'll leave this open for now as there's an action on me to make a change either way.