0

I am trying to use SocketRocket (an Objective-C pod) from Swift 2. I have creating a bridging header.

Here is what I am trying:

import SocketRocket
class WS3: NSObject, SRWebSocketDelegate {
    func websocket(webSocket: SRWebSocket!, 
                   didReceiveMessage message: AnyObject!) -> Void {
    }
}

And the compiler error message is:

Error:Error:Build failed with 1 error and 0 warnings in 1s 685ms
/Users/jao/Desktop/consulting/blackring/Black Ring/Black Ring/WS3.swift
    Error:Error:line (8)type 'WS3' does not conform to protocol 'SRWebSocketDelegate'
    x86_64
    Note:Note:class WS3: NSObject, SRWebSocketDelegate {
    Note:Note:      ^
    Note:Note:    public func webSocket(webSocket: SRWebSocket!, didReceiveMessage message: AnyObject!)
    Note:Note:                ^
SocketRocket.SRWebSocketDelegate
    Note:Note:protocol requires function 'webSocket(_:didReceiveMessage:)' with type '(SRWebSocket!, didReceiveMessage: AnyObject!) -> Void'

It looks to me like I'm doing exactly what the error message says I should be doing. What am I doing wrong?

Jack Orenstein
  • 169
  • 2
  • 9

1 Answers1

1

I figured it out.

didReceiveMessage method is declared required in protocol. The problem is with your method signature. Your didReceiveMessage method signature does not match with the protocol's method signature.

Replace it:

func websocket(webSocket: SRWebSocket!,
        didReceiveMessage message: AnyObject!) -> Void {
    }

With:

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

}

This is exactly what the Xcode is complaining about that required method of protocol is missing.

I tested it at my end and it is working fine.

Tip: Please try to use Xcode's intellisense to avoid these kinds of errors.

Muhammad Zeeshan
  • 2,441
  • 22
  • 33
  • please note, that the trouble is the name of the function ... You are right, but i recognized it while reading your answer the second time :-). up voted! – user3441734 Feb 16 '16 at 07:16
  • I also found the incorrect case. I don't know why that took me so long. What is in IntelliSense? – Jack Orenstein Feb 16 '16 at 14:51
  • Intellisense is when you type few starting character then xcode gives you some related suggestions then select the appropriate suggestion and press enter the whole thing will be written for you automatically. Like in this case i just conforms to the protocol and type webSocket after that i just selected the appropriate method from suggestions thats it. – Muhammad Zeeshan Feb 16 '16 at 19:20
  • If this answer solves your problem please mark it as correct. Thank you. – Muhammad Zeeshan Mar 16 '16 at 05:20