0

I am trying to import a swift class to my objective-c project but I get "Use of undeclared identifier" error inside my .m file when I try to use the swift class.

Inside my swift class there is an "@objc" marker. When I created the swift class I added the bridge file. I also checked those values:

Defines Module : YES

Always Embed Swift Standard Libraries : YES

Install Objective-C Compatibility Header : YES

Also in Target/Build Settings/Objective-c Bridging Header I checked that the path to the bridging file is correct.

What am I doing wrong? Do I have to write something inside the bridging file?

Community
  • 1
  • 1
Student
  • 3
  • 3
  • How did you import your swift file to objective c? Add some relevant code, related to that bridging file and import statement – Midhun MP Mar 26 '19 at 12:34
  • I created a new .swift file and copy paste the code. The bridging file created autonomously by Xcode. – Student Mar 26 '19 at 12:34
  • So you imported that "modulename-Swift.h" in your objective c file ? – Midhun MP Mar 26 '19 at 12:47
  • Please refer this ~> https://stackoverflow.com/questions/24102104/how-can-i-import-swift-code-to-objective-c – Jatin Patel Mar 26 '19 at 12:49
  • @MidhunMP yes I did, but when I try to use the swift class I get this error – Student Mar 26 '19 at 12:51
  • @MidhunMP Actually the name of the file is "myapp-Bridging-Header.h" – Student Mar 26 '19 at 12:57
  • Recheck all your points by refering this https://medium.com/@nimjea/swift-objective-c-mixed-languages-app-16b6c9c3e9b0 – dahiya_boy Mar 26 '19 at 12:58
  • @Student No, you are using the wrong bridging header – Midhun MP Mar 26 '19 at 12:58
  • @MidhunMP which one is the correct then?This file was generated from xcode. – Student Mar 26 '19 at 12:59
  • @Student This bridging header is to expose ObjC classes to Swift, you need to use the bridging header which is generated automatically when you build the project. Which is not added to project – Midhun MP Mar 26 '19 at 12:59
  • Usually the bridging header name will be, your targetname-Swift.h. Check the links attached by @dahiya_boy – Midhun MP Mar 26 '19 at 13:01
  • @MidhunMP but when I try to build the project it fails. – Student Mar 26 '19 at 13:09
  • @MidhunMP I checked the link, but I can't figure it out. How to create this myapp-Swfit.h? Manually? I actually did and linked it to the Objective-C Bridging Header but the problem remains. – Student Mar 26 '19 at 13:21
  • @Student: You don't need to create that file manually, it will be generated automatically. It's not replace `myapp` with your target/app name. – Midhun MP Mar 27 '19 at 04:20

0 Answers0