Objective-C Bridging Header not getting created with Xcode 8
Asked Answered
C

5

48

I am trying to add objective-c libraries to my Swift 3 project (Xcode 8 IDE). But objective c interface header is not getting generated automatically. I tried to add bridging header manually but showing linking error saying bridging header .h is not found. Any help would be appreciated :)

Crim answered 21/9, 2016 at 11:10 Comment(0)
C
163

Here the solution for the issue.

  • Create a new header file and name it like "your project name-Bridging-Header.h". The file must be saved to your project folder
  • Select your xcode project -> select your build target -> select build settings -> click the "all" option at the top -> search for Swift Compiler - General
  • Select Objective-C Bridging Header item and double click on its value field (right side of the same row). One popup would appear and there you can enter your bridging header file path (Follow the below steps to provide header file path).
  • Open finder and drag and drop your bridging header file to the popup. Now it will create an absolute path for bridging header. To make relating path, you can give the path as $(PROJECT_DIR)/$(PROJECT_NAME)/$(PROJECT_NAME)-Bridging-Header.h

  • Click outside for the value get saved. Done!! Now you can import your Objective-C libraries (eg. #import "SVProgressHUD.h") to bridging file and start using it in your swift project.

Hope this would be helpful to someone. :)

Crim answered 21/9, 2016 at 11:22 Comment(7)
Is that different from the procedure described in https://mcmap.net/q/16036/-how-do-i-call-objective-c-code-from-swift, starting at "In some situations, particularly when working with ObjC frameworks, ..." ?Jemie
If you drag and drop, you'll get an absolute path, you can replace the project path with $(SRCROOT) to make it relativeGuitarist
what if there is no "Swift Compiler - General" ?Soke
@Aleksandr I have been spending the last hour searching for an answer to this issue as I had the same problem.... Select "ALL" at the top and you should be able to find it.Inhalant
@JohanTingbacke Great ! You saved me :) And it's kinda embarrassing that problem was so easy to resolve)Soke
Root directory of my project name contains spaces between words. And I have put bridging header file under main target. So while adding bridging header file to "Objective-C Bridging Header", I will also have to write root directory name and it contains spaces. Could you say how should I specify my bridging header file name?Loera
An even easier way is to drop an empty .m file onto the project. Xcode will now prompt you to create the bridging header automatically.Substitutive
F
16

Objective C Header file creation steps

  1. File -> New -> File -> Header File

  2. Name your Header file like this yourAppName-Bridging-Header

  3. Now click on your Project -> Build Settings

  4. Change from Basic to All

  5. Search Bridging

  6. You will get the search result as shown in the below image

enter image description here

after Adding

enter image description here

  1. In that double click the right of Objective-C Bridging Header and enter as follows

    eg, yourAppName/yourAppName-Bridging-Header.h

  2. You need to import as follows

enter image description here

  1. Thats All

Happy Coding :)

Fassold answered 27/3, 2018 at 9:13 Comment(0)
E
2

It seems easiest to simply create a new Objective-C File and have Xcode take care of all the nitty gritty of setting up everything. Once that's done, you can delete the Objective-C file.

  1. Right Click in the project explorer and choose new file
  2. Selected Objective-C File
  3. Name it delete_me or something
  4. You'll get prompted to have a bridging file created and say yes
  5. Delete the file you created (perhaps delete_me.m)
Estellaestelle answered 25/2, 2019 at 23:46 Comment(1)
I'm not getting prompeted step 4.Hippocrates
A
1

In the case of multiple targets, make sure the swift classes are members of that target, or else the file will not be generated.
Xcode 8.3

Amir answered 23/8, 2017 at 20:0 Comment(0)
P
0

Swift 5

Easy way

1--cmd+n 
              then select 
2--Objective-C File (name your file it like this YourAppName-Bridging-Header)

       if popup arrive for bridging header then select 

3--YES
       if not 
       //MARK:-click on your 
4--Project->BuildSettings
       //MARK:- in search     
5--Bridging Header
6--Double click and paste bottom line and done
$(PROJECT_DIR)/$(PROJECT_NAME)/$(PROJECT_NAME)-Bridging-Header.h
Pollerd answered 3/3, 2020 at 11:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.