Swift classes not found in Objective-C project

与世无争的帅哥 提交于 2019-12-13 13:58:07

问题


I am working on an iOS project developed using Objective-C. I need to integrate some Swift files in it. So, did following:

  1. Added a new Swift file named "temp", so that MyProject-Bridging-Header.h is added by my Xcode IDE (Version 9.1).
  2. Added the Swift files, which I want to use, to the project.
  3. Changed target setting Defines Module to YES.
  4. Similarly, "Product Module Name" is set to "MyProject".
  5. I can see the MyProject-swift.h a file name for the setting "Objective-C Generated Interface Header Name".
  6. Added import statement for myProject-swift.h in one of my Objective-C .m files and was able to build the project successfully.
  7. I checked in Finder that myProject-swift.h was created.
  8. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!