Created
March 18, 2024 14:56
-
-
Save adrianjagielak/342745ccb401d80a40ea9e1593debbd3 to your computer and use it in GitHub Desktop.
Obtaining NWEndpoint host & port
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let connection = NWConnection(to: result.endpoint, using: .tcp) | |
connection.stateUpdateHandler = { state in | |
switch state { | |
case .ready: | |
if let innerEndpoint = connection.currentPath?.remoteEndpoint, | |
case .hostPort(let host, let port) = innerEndpoint | |
{ | |
print("Connected to", "\(host):\(port)") | |
} else { | |
print("Failed finding ip:host") | |
} | |
connection.stateUpdateHandler = nil | |
connection.cancel() | |
default: | |
break | |
} | |
} | |
connection.start(queue: .global()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment