Skip to content

Instantly share code, notes, and snippets.

@siracusa
Created April 8, 2025 21:20
Show Gist options
  • Save siracusa/68e3b56cd9b32c5f42351f9b851b54c6 to your computer and use it in GitHub Desktop.
Save siracusa/68e3b56cd9b32c5f42351f9b851b54c6 to your computer and use it in GitHub Desktop.
A Logger call with an interpolated value stops this code from compiling.
import OSLog
import Network
import Foundation
let logger = Logger(subsystem: "com.example.demo", category: "Default")
let connection = NWConnection(host: NWEndpoint.Host("time.apple.com"), port: 123, using: .udp)
// The line below fails to compile: Type of expression is ambiguous without a type annotation
connection.stateUpdateHandler = { state in
// Comment out this logger call (or remove the interpolated
// "state" variable) to fix the compilation error.
logger.debug("stateUpdateHandler: \(state, privacy: .public)")
switch state {
case .ready:
print("ready")
default:
break
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment