1

I can't reference SomeSwiftProtocol from my Objective-C header files.

Do you know how can it be done?


My protocol is defined like this:

@objc protocol SomeSwiftProtocol : class {
  func someFunc()
}

It is well defined (not like here) because I can use it from .m files by importing the Swift bridging header:

#import "MyProject-Swift.h"

But that import is not found when I put it in .h files.

For example, this is SomeClass.h:

// This import is not found...
#import "MyProject-Swift.h"

// ...so the protocol is not found
@interface SomeClass : UIView<SomeSwiftProtocol>
@end
Ferran Maylinch
  • 10,919
  • 16
  • 85
  • 100
  • 1
    Does this work: https://stackoverflow.com/a/28329497/1187415 ? – Martin R Jun 26 '17 at 14:31
  • 2
    You probably have an import loop (Swift -> bridging header -> SomeClass.h -> Swift), – a forward declaration of the protocol, such as shown in the answer Martin links to, should work. – Hamish Jun 26 '17 at 14:34
  • I tried with a forward declaration of the protocol in the header, but I get this warning there: `Cannot find protocol definition for 'SomeSwiftProtocol'`. – Ferran Maylinch Sep 27 '17 at 16:46

0 Answers0