Use of undeclared identifier when I want use swift file in objective c project

3.5k Views Asked by At

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

1

There are 1 best solutions below

0
Rizwan Ahmed On

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 :)