简体   繁体   English

Swift中GCDAsyncUDPSocket getHost的哪些数据类型

[英]What data types for GCDAsyncUDPSocket getHost in swift

I'm confused. 我糊涂了。 Here is my code: 这是我的代码:

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

Here is my error: 这是我的错误:

在此处输入图片说明

Cannot invoke 'getHost' with an argument list of type '(inout AutoreleasingUnsafeMutablePointer, port: inout UnsafeMutablePointer, fromAddress: NSData!)' 无法使用类型为'(inout AutoreleasingUnsafeMutablePointer,port:inout UnsafeMutablePointer,fromAddress:NSData!)的参数列表调用'getHost'。

And here is the "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

To me that looks like you pass in: 在我看来,您传递了:

AutoreleasingUnsafeMutablePointer<NSString?>

and a 和一个

UnsafeMutablePointer<UInt16> which I thought I did. 我以为是UnsafeMutablePointer<UInt16>

Any ideas where I went wrong? 有什么想法我做错了吗?

You have to define the variables as 您必须将变量定义为

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

With & the variables are passed as an inout-argument to the function taking the corresponding UnsafeMutablePointer parameters. 使用&将变量作为inout参数传递给采用相应UnsafeMutablePointer参数的函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM