[英]Instance method nearly matches optional Requirement
I have a class in swift which implements SRWebSocketDelegate
protocol written in objective-c. 我在swift中有一个类,它实现了用objective-c编写的
SRWebSocketDelegate
协议。 When I try to implement it's optional method webSocketDidOpen
, then I get the following warning: 当我尝试实现它的可选方法
webSocketDidOpen
,我收到以下警告:
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)
此外,当我运行我的代码时,没有调用webSocketDidOpen的实现,代码直接转到
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? 如何实现我在Objective-C中编写的协议的可选方法,并消除这些警告?
Thanks in advance! 提前致谢!
SRWebSocket.h
is annotated NS_ASSUME_NONNULL_BEGIN
, so by default all values are nonnull
. SRWebSocket.h
注释NS_ASSUME_NONNULL_BEGIN
,因此默认情况下所有值都是nonnull
NS_ASSUME_NONNULL_BEGIN
。 That means that this: 这意味着:
- (void)webSocketDidOpen:(SRWebSocket *)webSocket;
Is imported as: 导入为:
func webSocketDidOpen(_ webSocket: SRWebSocket)
But you implemented: 但你实施了:
func webSocketDidOpen(_ webSocket: SRWebSocket!)
SRWebSocket
is not the same type as SRWebSocket!
SRWebSocket
与SRWebSocket!
类型SRWebSocket!
. 。 Remove the
!
删除
!
. 。 This is likely what the rename fixit will do for you.
这可能是重命名fixit将为您做的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.