Implementin SRWebSocketDelegate in Swift

870 views Asked by At

I am implementing:

@protocol SRWebSocketDelegate <NSObject>

- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message;

@optional

- (void)webSocketDidOpen:(SRWebSocket *)webSocket;
- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error;
- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean;

in Swift. All functions I can implement ok and works, but didCloseWithCode I just can't make it to work.

I am having trouble implementing

- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean;

in Swift.

I am trying:

func webSocket(webSocket: SRWebSocket!, didCloseWithCode code: NSInteger!, reason: NSString!, wasClean: Bool!) {
    println("websocket closed: \(reason)")
    self.connect(5.0)
}

with no luck.

1

There are 1 answers

0
john07 On
func webSocketDidOpen(webSocket: SRWebSocket!) {
    DDLogInfo("socket opened");
}

func webSocket(webSocket: SRWebSocket!, didCloseWithCode code: Int, reason: String!, wasClean: Bool) {
    DDLogError("code: \(code) reason:\(reason) ");
}

func webSocket(webSocket: SRWebSocket!, didFailWithError error: NSError!) {
    DDLogError("error: \(error)");
}

func webSocket(webSocket: SRWebSocket!, didReceiveMessage message: AnyObject!) {
}