简体   繁体   English

实例方法几乎匹配可选的Requirement

[英]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! SRWebSocketSRWebSocket!类型SRWebSocket! . Remove the ! 删除! . This is likely what the rename fixit will do for you. 这可能是重命名fixit将为您做的事情。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 实例方法 'application(application:handleOpenURL:)' 几乎匹配可选要求 - Instance method 'application(application:handleOpenURL:)' nearly matches optional requirement Swift 3 warning func collectionView实例方法几乎匹配可选要求 - Swift 3 warning func collectionView instance method nearly matches optional requirement 实例方法“ xyz()”几乎与协议“ ABDelegate”的可选要求“ xyz()”匹配 - Instance method 'xyz()' nearly matches optional requirement 'xyz()' of protocol 'ABDelegate' 实例方法“ mapView(_:didFailToLocateUserWithError :)”几乎与可选要求匹配 - Instance method 'mapView(_:didFailToLocateUserWithError:)' nearly matches optional requirement 实例方法'widgetPerformUpdate(completionHandler :)'几乎匹配可选要求'widgetPerformUpdate(completionHandler :)' - Instance method 'widgetPerformUpdate(completionHandler:)' nearly matches optional requirement 'widgetPerformUpdate(completionHandler:)' UNUserNotificationCenterDelegate委托方法“几乎匹配可选要求” - UNUserNotificationCenterDelegate delegate method “nearly matches optional requirement” Swift 中的“实例方法几乎匹配可选要求”,当它应该是完美匹配时 - "Instance method nearly matches optional requirement" in Swift when it should be a perfect match application(_:didFinishLaunchingWithOptions :)'几乎匹配可选要求 - application(_:didFinishLaunchingWithOptions:)' nearly matches optional requirement 'textFieldDidBeginEditing' 几乎匹配 Swift 中协议 'UITextFieldDelegate' 的可选要求 'textFieldDidBeginEditing' - 'textFieldDidBeginEditing' nearly matches optional requirement 'textFieldDidBeginEditing' of protocol 'UITextFieldDelegate' in Swift 如何从didRegisterForRemoteNotificationsWithDeviceToken函数ios swift 3中删除几乎匹配的可选需求警告? - How to remove the nearly matches optional requirement warning from didRegisterForRemoteNotificationsWithDeviceToken function ios swift 3?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM