Reputation: 1569
I'm working on an iOS project that contains Swift and Objective-C Classes.
To instantiate an object described in Objective-C, I've understand that I needed to have a Bridging-Header file that contains all the imports of the headers I will have to use on my Swift classes. And it works great on my project. I made all classes I needed, I subclassed Objective-C classes in Swift, everything is OK.
My problem is when it comes to do the opposite: instantiate a swift object in an Objective-C file. So I read that I need to have those options:
#import "<#YourProjectName#>-Swift.h"
on the *.m file I'm working on.And that is what I did:
I changed all the values on the Build Settings that needed to be changed. I added the import
line, I even tried to create the header file, but I still have the "<#YourProjectName#>-Swift.h" file not found
error.
Of course, I replaced the YourProjectName by the actual module name, the one I found under Product Module Name in Packaging section on Build Settings. Also, there is no spaces in the Project Name.
Did I forgot a step?
Upvotes: 11
Views: 4293
Reputation: 4070
Make sure you are importing the -Swift.h
file from a .m Objective-C file and not a .h header file. The docs only talk about importing from .m:
... import the Xcode-generated header file for your Swift code into any Objective-C .m file you want to use your Swift code from.
The -Swift.h
file is generated during the build and I've found that importing it from a .h file always fails, even when I know the file exists. Since it's generated by the build, I'm guessing it's cleaned out when the compiler is sifting through the headers and regenerated once the .swift files are compiled.
Upvotes: 8