问题
I am working on an iOS project developed using Objective-C. I need to integrate some Swift files in it. So, did following:
- Added a new Swift file named "temp", so that
MyProject-Bridging-Header.h
is added by my Xcode IDE (Version 9.1). - Added the Swift files, which I want to use, to the project.
- Changed target setting
Defines Module
to YES. - Similarly, "Product Module Name" is set to "MyProject".
- I can see the
MyProject-swift.h
a file name for the setting "Objective-C Generated Interface Header Name". - Added import statement for
myProject-swift.h
in one of my Objective-C .m files and was able to build the project successfully. - I checked in Finder that
myProject-swift.h
was created. - Ensured the @obj prefix in the Swift classes declaration.
Still, when I try to use any of the Swift classes, then I get compile time error "User of undeclared identifier".
What can be the reason for the issue? Am I missing something?
回答1:
Figured it out...
I was missing the forward declaration of the Swift class in my Objective-C class. All I needed to do was to add following statement before the interface declaration in the .h
file.
@class MySwiftClassName;
Once the statement was added, it's building successfully.
来源:https://stackoverflow.com/questions/48009259/swift-classes-not-found-in-objective-c-project