This question is basically the same as this one, but that one went unanswered.
TL;DR: Protocol does not show up in MyProject-Swift.h
secret bridging file. And so (not unexpectedly) the Obj-C code can't find it.
I have been able to duplicate it in a from-scratch project. Here is what I did.
- Create new one-view iOS Objective-C project.
- Add a new Swift
UIView
subclass via "New File" menu. - Confirm that
MyProject-Bridging-Header.h
was created. (Visibly) - Confirm that the secret
MyProject-Swift.h
file was automatically created. (Way down there inDerivedData/.../DerivedSources
). - Add an instance of this View to my
ViewController.m
. - Include the
MyProject-Swift.h
file inViewController.m
. - Successfully build -- sanity check
Now for the weirdness...
- Add a Swift protocol file via "New File" menu.
- Make
ViewController
conform to and implement this protocol. Build fails at this spot in
ViewController.m
:#import "MyProject-Swift.h" @interface ViewController () <MyProtocol> // Can't find protocol declaration
Examining the MyProject-Swift.h
file confirms that the protocol is not in there. But poking around some big pre-existing hybrid projects (that do build) I don't see any protocols in any of their -Swift.h
files.
How do Swift protocols get recognized in Objective-C?