swift 中 GCDAsyncUDPSocket getHost 的数据类型
What data types for GCDAsyncUDPSocket getHost in swift
我很困惑。这是我的代码:
public func udpSocket(sock: GCDAsyncUdpSocket!, didReceiveData data: NSData!, fromAddress address: NSData!, withFilterContext filterContext: AnyObject!) {
var send_port : UnsafeMutablePointer<UInt16>
var hostPtr : AutoreleasingUnsafeMutablePointer<NSString?>
// This appears to be a class level function - not an individual function attached to the sock variable
GCDAsyncUdpSocket.getHost(&hostPtr, port: &send_port, fromAddress: address)
}
这是我的错误:
无法使用类型为“(inout AutoreleasingUnsafeMutablePointer, port: inout UnsafeMutablePointer, fromAddress: NSData!)”
的参数列表调用 'getHost'
这里是 "prototype"
class func getHost(hostPtr: AutoreleasingUnsafeMutablePointer<NSString?>, port portPtr: UnsafeMutablePointer<UInt16>, fromAddress address: NSData!) -> Bool
class func getHost(hostPtr: AutoreleasingUnsafeMutablePointer<NSString?>, port portPtr: UnsafeMutablePointer<UInt16>, family afPtr: UnsafeMutablePointer<Int32>, fromAddress address: NSData!) -> Bool
对我来说,你似乎通过了:
AutoreleasingUnsafeMutablePointer<NSString?>
还有一个
UnsafeMutablePointer<UInt16>
我以为我做到了。
有什么地方出错了吗?
您必须将变量定义为
var send_port : UInt16 = 0
var hostPtr : NSString? = nil
使用 &
变量作为输入参数传递给函数
取相应的 UnsafeMutablePointer
参数。
我很困惑。这是我的代码:
public func udpSocket(sock: GCDAsyncUdpSocket!, didReceiveData data: NSData!, fromAddress address: NSData!, withFilterContext filterContext: AnyObject!) {
var send_port : UnsafeMutablePointer<UInt16>
var hostPtr : AutoreleasingUnsafeMutablePointer<NSString?>
// This appears to be a class level function - not an individual function attached to the sock variable
GCDAsyncUdpSocket.getHost(&hostPtr, port: &send_port, fromAddress: address)
}
这是我的错误:
无法使用类型为“(inout AutoreleasingUnsafeMutablePointer, port: inout UnsafeMutablePointer, fromAddress: NSData!)”
的参数列表调用 'getHost'这里是 "prototype"
class func getHost(hostPtr: AutoreleasingUnsafeMutablePointer<NSString?>, port portPtr: UnsafeMutablePointer<UInt16>, fromAddress address: NSData!) -> Bool
class func getHost(hostPtr: AutoreleasingUnsafeMutablePointer<NSString?>, port portPtr: UnsafeMutablePointer<UInt16>, family afPtr: UnsafeMutablePointer<Int32>, fromAddress address: NSData!) -> Bool
对我来说,你似乎通过了:
AutoreleasingUnsafeMutablePointer<NSString?>
还有一个
UnsafeMutablePointer<UInt16>
我以为我做到了。
有什么地方出错了吗?
您必须将变量定义为
var send_port : UInt16 = 0
var hostPtr : NSString? = nil
使用 &
变量作为输入参数传递给函数
取相应的 UnsafeMutablePointer
参数。