简体   繁体   中英

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!)'

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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