1

I have a class in swift which implements SRWebSocketDelegate protocol written in objective-c. When I try to implement it's optional method webSocketDidOpen, then I get the following warning: enter image description here

Also, when I run my code the implementation for webSocketDidOpen is not getting called and the code directly goes to webSocket(_ webSocket: SRWebSocket, didReceiveMessageWith string: String)

How do I implement the optional methods of my protocol written in Objective-C and also get rid of these warnings?

Thanks in advance!

4

1 回答 1

3

SRWebSocket.h已注释NS_ASSUME_NONNULL_BEGIN,因此默认情况下所有值都是nonnull. 这意味着:

- (void)webSocketDidOpen:(SRWebSocket *)webSocket;

导入为:

func webSocketDidOpen(_ webSocket: SRWebSocket)

但是你实现了:

func webSocketDidOpen(_ webSocket: SRWebSocket!)

SRWebSocket不是同一类型SRWebSocket!。删除!. 这很可能是 rename fixit 将为您做的事情。

于 2017-07-19T15:35:14.910 回答