fcbflying
fcbflying

Reputation: 703

swift CocoaAsyncSocket connectToHost method arguments error

I define properties as bellow:

let addr:String = "192.168.31.218"
let port :UInt16 = 8000
let timeout:Double = 5.0
var socket: GCDAsyncSocket!
var errPtr : NSError?

and I call the method as bellow:

socket.connectToHost(addr, onPort: port, withTimeout: timeout, error:&errPtr)

The xcode7 reminder me:

Cannot invoke 'connectToHost' with an argument list of type '(NSString, onPort: UInt16, withTimeout: Double, error: inout NSError?)'

The method signature is:

  • (BOOL)connectToHost:(NSString *)hostname onPort:(UInt16)port withTimeout:(NSTimeInterval)timeout error:(NSError **)errPtr

It is strange that it works in xcode6.4 with swift1.2, but now I upgrade it in xcode7 with swift2.0. Above error happens.

Upvotes: 0

Views: 630

Answers (1)

su-
su-

Reputation: 58

try this!!

    do {
        try socket.connectToHost(addr, onPort: port, withTimeout: timeout)
    } catch let e {
        print(e)
    }

It's working for me.(Xcode:7 or later, CocoaAsyncSocket: 7.4.2)

Upvotes: 1

Related Questions