swift中GCDAsyncUDPSocket getHost的数据类型

时间:2015-06-29 21:38:55

标签: ios swift gcdasyncsocket

我很困惑。这是我的代码:

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)       
}

这是我的错误:

enter image description here

无法调用&#39; getHost&#39;使用类型&#39;的参数列表(inout AutoreleasingUnsafeMutablePointer,port:inout UnsafeMutablePointer,fromAddress:NSData!)&#39;

这是&#34;原型&#34;

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>我认为我做过。

我出错的任何想法?

1 个答案:

答案 0 :(得分:1)

您必须将变量定义为

var send_port : UInt16 = 0
var hostPtr : NSString? = nil

使用&,变量作为inout-argument传递给函数 取相应的UnsafeMutablePointer参数。