I have an Objective-C protocol which I'm trying to implement in a Swift class. For example:
@class AnObjcClass; @protocol ObjcProtocol <NSObject> - (void)somethingWithAnArgument:(AnObjcClass *)arg; @end
When I try to conform to it in a Swift class like this:
@objc class SwiftClass: NSObject, ObjcProtocol { // ... }
I get the following scary compiler error:
Type "SwiftClass" cannot conform to protocol "ObjcProtocol" because it has requirements that cannot be satisfied.
How do I resolve this?
Ensure any classes referenced by that protocol are included in your bridging header.
This error happens when one of the types used in the protocol (the protocol itself, a return type, an argument type) is not included in your Swift bridging header.
Objective-C classes can happily implement this protocol because of the @class AnObjcClass
forward declaration, but it appears that Swift classes can't implement protocols which use classes that are only forward-declared.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With