3

when I want use swift file in objective c project and I declare an object from swift class, I get "Use of undeclared identifier" error. the way that I pass:

  1. coping swift file in project and type @objc before declare swift class

  2. create header file in project manually

  3. set "Defines module" in target to Yes

  4. set objective-C bridging header in target to $(SRCROOT)/$(PRODUCT_MODULE_NAME)-Bridging-Header.h

  5. declare #import "productModuleName-Bridging-Header.h" in objective-c file

  6. use name_of_swift_class *s = [[name_of_swift_class alloc] init];

when I want use swift file in step 6 I get "Use of undeclared identifier" error. why?!!! do I have the mistake?

when I test this steps in new project I don't get error but in project that I want it return error.

thank you for your help

Somaye Sabeti
  • 31
  • 1
  • 4
  • You could also get this error when placing 'MyProject-Swift.h' within #ifdef FB_SONARKIT_ENABLED or #if DEBUG - then it works in simulator but not when building a release.. – scbojer Mar 04 '21 at 10:13

1 Answers1

2

The problem is at Step 5 You should not be importing "productModuleName-Bridging-Header.h" instead you should be importing "productModuleName-Swift.h"

P.S- After making this change clean your project, clear your derived data and build it. It will work. Hope it helps :)

Rizwan Ahmed
  • 919
  • 13
  • 19