gpt4 book ai didi

ios - 无法使用类型的参数列表调用 'bindToPort'

转载 作者:行者123 更新时间:2023-11-30 13:50:18 24 4
gpt4 key购买 nike

我正在尝试使用 GCDAsyncUdpSocket,但在使用 bindToPort 和 beginReceiving 函数时出现这些错误。

无法使用类型的参数列表调用“bindToPort”
'&' 与类型 '()' 的非 inout 参数一起使用

class UDPServer: NSObject, GCDAsyncUdpSocketDelegate {

let IP = "255.255.255.255"
let PORT:UInt16 = 2052
var sock:GCDAsyncUdpSocket!

override init() {
super.init()
setupConnection()
}

func setupConnection() {
var err: NSError?
sock = GCDAsyncUdpSocket(delegate: self, delegateQueue: dispatch_get_main_queue())
sock.bindToPort(PORT, error: &err)
sock.beginReceiving(&err)
}
}

我在这里缺少什么?

最佳答案

我使用了 try/catch block 和另一个签名。这可能会在较新版本的 CocoaAsyncSocket 中发生变化

func setupConnection(){
udpSocket = GCDAsyncUdpSocket(delegate: self, delegateQueue: dispatch_get_main_queue())

do {
try udpSocket.bindToPort(PORT)
try udpSocket.beginReceiving()
} catch let err as NSError {
err.description
}
}

关于ios - 无法使用类型的参数列表调用 'bindToPort',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34377653/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com