4

I have created a Swift project and imported Objective-C files. During import Xcode asked me to create a bridging header and created a header.

Now in the Objective-C files of the same project I want to use Swift class methods. I googled about importing Swift code in an Objective-C file. I found that we have to import ProjectName-Swift.h in the Objective-C file. My questions are as follows:

  1. ProjectName-Swift.h is not been created by Xcode. How do I create that file?
  2. After creation of ProjectName-Swift.h file, how do I use the Swift file methods in Objective-C files?
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Rakesh
  • 1,177
  • 1
  • 15
  • 31

1 Answers1

2

This seems really messed up, but the ProjectName-Swift.h file isn't visible. You just have to #import ProjectName-Swift.h in your Obj-C classes, and it'll work.

NRitH
  • 13,441
  • 4
  • 41
  • 44
  • thank you for quick reply. I tried #import ProjectName-Swift.h but that file has not generated yet. Can i create it manually?. – Rakesh Sep 04 '15 at 13:43
  • 1
    No, it's created as part of the build process. If you clean your project, it will complain about he file being missing, but it'll be regenerated. You are using your own project's name in place of ProjectName, right? – NRitH Sep 04 '15 at 16:35
  • Yes i am using my own project name. I tried by cleaning my project and after that tried to #import ProjectName-Swift.h but XCODE not generating intelligence for this lit it does for other file while importing. – Rakesh Sep 05 '15 at 07:41
  • It isn't visible but it will be generated in the Derived Data folder by default. Mine was generated here: DerivedData/TestProject-aqpeqeuqusyzdtcqddjdixoppyqn/Build/Intermediates/TestProject.build/Debug-iphoneos/TestProject.build/DerivedSources/TestProject-Swift.h – Riddick Jan 13 '17 at 10:51