简体   繁体   English

不符合协议Swift父类-目标C协议

[英]does not conform to protocol Swift Parent Class - Objective C Protocol

I am trying to call my Protocol Class in Swift, but its giving me Error 我正在尝试在Swift中调用我的协议类,但是它给了我错误

"Type SwiftViewController does not conform to protocol ABCDelegate. “类型SwiftViewController不符合协议ABCDelegate。

Could you please tell me what I am missing , as I find other posts , but nothing is explained properly , also let me know if you need more info. 当我找到其他帖子时,能否请您告诉我我所缺少的内容,但没有正确解释,也请告知我是否需要更多信息。

@protocol ABCDelegate <NSObject>
@required
- (void) ABC:(NSString*)MessageResponseStr
@end
@interface ABC : NSObject

@property (nonatomic, assign) id<ABCDelegate> delegate;
@property(nonatomic,retain)NSString *ResponseStr;
-(void)Network:(int)NetworkState 

A protocol defines abstract behaviour. 协议定义抽象行为。

Like interface in many other languages. 与其他许多语言一样的界面。 ABCDelegate protocol simply states: Anything that will implement me, need to specify the following required methods, and can choose to implement the following optional methods. ABCDelegate协议简单地声明:任何将实现我的东西,需要指定以下必需的方法,并且可以选择实现以下可选方法。

In your case, your class need to implement the protocol required ABC method. 在您的情况下,您的类需要实现协议所需的ABC方法。

When you defined the protocol in ABC class, you declared the protocol method to be @required as in - 当您在ABC类中定义协议时,您将协议方法声明为@required如-

@protocol ABCDelegate <NSObject>
@required
- (void) ABC:(NSString*)MessageResponseStr
@end

Now in SwiftViewController or any class that implements the protocol, it has become mandatory to add the - (void) ABC:(NSString*)MessageResponseStr because of the @required keyword. 现在,在SwiftViewController或实现协议的任何类中,由于@required关键字,已强制添加- (void) ABC:(NSString*)MessageResponseStr

As soon as you implement the method, error will go away. 一旦实现该方法,错误就会消失。

Hope this helped. 希望这会有所帮助。

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

相关问题 Swift 类不符合带有错误处理的 Objective-C 协议 - Swift class does not conform to Objective-C protocol with error handling 使swift类符合定义属性的objective c协议 - Make swift class conform to objective c protocol that defines properties Objective-c 类可以符合 swift 协议吗? - Can an objective-c class conform to a swift protocol? 如何使Objective-C类符合Swift中定义的协议? - How to make an Objective-C class conform to a protocol defined in Swift? Swift中的Objective-C协议 - 显示不符合错误 - Objective-C protocol in Swift - shows does not conform error 迅速不符合Objective-C协议 - Cannot conform to objective-c protocol in swift Objective-C 警告:Class 'ViewController' 不符合协议 'CBPeripheralManagerDelegate' - Objective-C warning: Class 'ViewController' does not conform to protocol 'CBPeripheralManagerDelegate' 类不符合NSItemProviderWriting协议-Objective-C - Class does not conform to NSItemProviderWriting protocol - Objective-C Swift ViewController,目标C协议,类型&#39;ViewController&#39;不符合协议&#39;MyProtocolDelegate&#39; - Swift ViewController, objective C protocol, Type 'ViewController' does not conform to protocol 'MyProtocolDelegate' Objective-C:将一个实现协议的类别添加到现有类中,是否使对象符合该协议? - Objective-C: Does adding a Category, that implements a Protocol, to an existing Class, make Objects conform to that Protocol?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM