Xcode MyProjectName-Bridging-Header.h does not exist

I want to start using Swift in my Objective-C project. So I added a quick class:

import Foundation @objc class System : NSObject { @objc func printSome() { println("Print line System"); } } 

And imported it into the .m file:

#import "MyProjectName-Swift.h"

When creating my project, I get the following error:

 Bridging header 'PathToMyProject/MyProjectName-Bridging-Header.h' does not exist 

NOTE. Under "Build Options-> Swift-Compiler - Code Generation -> Objective-C Invalid Header" is set to MyProjectName-Bridging-Header.h

What should I do to solve this problem?

Any help is greatly appreciated.

EDIT: bridge header file: #if defined (__ has_include) && & __has_include () # include #endif

 #include <objc/NSObject.h> #include <stdint.h> #include <stddef.h> #include <stdbool.h> #if defined(__has_include) && __has_include(<uchar.h>) # include <uchar.h> #elif __cplusplus < 201103L typedef uint_least16_t char16_t; typedef uint_least32_t char32_t; #endif #if !defined(SWIFT_PASTE) # define SWIFT_PASTE_HELPER(x, y) x##y # define SWIFT_PASTE(x, y) SWIFT_PASTE_HELPER(x, y) #endif #if !defined(SWIFT_METATYPE) # define SWIFT_METATYPE(X) Class #endif #if defined(__has_attribute) && __has_attribute(objc_runtime_name) # define SWIFT_RUNTIME_NAME(X) __attribute__((objc_runtime_name(X))) #else # define SWIFT_RUNTIME_NAME(X) #endif #if !defined(SWIFT_CLASS_EXTRA) # define SWIFT_CLASS_EXTRA #endif #if !defined(SWIFT_PROTOCOL_EXTRA) # define SWIFT_PROTOCOL_EXTRA #endif #if !defined(SWIFT_CLASS) # if defined(__has_attribute) && __has_attribute(objc_subclassing_restricted) # define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) SWIFT_CLASS_EXTRA # else # define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA # endif #endif #if !defined(SWIFT_PROTOCOL) # define SWIFT_PROTOCOL(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_PROTOCOL_EXTRA #endif #if !defined(SWIFT_EXTENSION) # define SWIFT_EXTENSION(M) SWIFT_PASTE(M##_Swift_, __LINE__) #endif #if !defined(OBJC_DESIGNATED_INITIALIZER) # if defined(__has_attribute) && __has_attribute(objc_designated_initializer) # define OBJC_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer)) # else # define OBJC_DESIGNATED_INITIALIZER # endif #endif #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wproperty-attribute-mismatch" #if defined(__has_feature) && __has_feature(modules) #endif #pragma clang diagnostic pop 
+98
ios objective-c xcode swift
Sep 29 '14 at 9:16
source share
12 answers

If the bridge file is created at the same level as the other classes, you may need to add a relative path, as these snapshots show. Note that the bridge file is created at the same level as the other classes: enter image description here

I entered the name correctly in the build settings, enter image description here

but the compiler does not find the file. enter image description here

Therefore, if I add a relative path from the project root (i.e. add ./ProjectName/BridgerFileName.h ), enter image description here

now it compiles, and I can call the method in my Objective-C class: enter image description here

+167
Dec 02 '14 at 22:49
source share
— -

I found that after manually creating the bridge header file and selecting the default name and location, the bridge header will be placed in the project directory, which is located in the root directory.

This requires the following value: Objectives> [Purpose of your application]> Build options> Swift compiler - Code generation> Objective-C Top-level console :

 $(SRCROOT)/$(PROJECT_NAME)/$(PROJECT_NAME)-Bridging-Header.h 

Please note that if your project is a quick module (framework), then, as indicated in the comments, you may prefer:

 $(SRCROOT)/$(PROJECT_NAME)/$(SWIFT_MODULE_NAME)-Bridging-Header.h 
+66
Feb 16 '15 at 10:25
source share

For those who remove the Bridging Header

I went the opposite way, like most of the other answers here. I used to use the Bridging Header, but I no longer need it. After I removed it from my project, I started getting the error mentioned in the question. I have completed the following steps to solve my problem.

  1. Go to Goals> [Purpose of your application]> Build Settings> Swift Compiler - General> Objective-C Bridging Header and delete the path. (Thanks to @Donamite for the idea.) (You can simply start typing the word "bridge" in the search field to find it.)
  2. Delete derived date. Go to Xcode> Preferences> Locations and click the gray arrow next to the Derived Data folder. Then delete your project folder.

enter image description here

+42
Apr 23 '16 at 6:55
source share

Adding a Bridge file to a Swift project.

Step 1. Go to File> Add Cocoa with Objective-C File (for temporary use)

enter image description here

Step 2. Then the following popup will appear. enter image description here

Now click the Create Bridging Header button

DONE
YOU RECEIVE A BUNDLE FILE IN BUNDLE
THANKS

+13
May 23 '16 at 12:39
source share

For me it helped to use $ (SRCROOT) / $ (PROJECT_NAME) / in front of my bridge for the bridge title

+12
Mar 27 '15 at 17:07
source share

These are the steps to create a Bridging header.

  1. File-> New → iOS-> Header file , name the bridge file as "yourProjectName-Bridging-Header.h".

  2. Build-Settings-> Objective-C Bridging Header , just name the Bridging header file as "ProjectName-Bridging-Header.h"

    NOTE. The bridge header file should be located in the main root folder of the project, where the ".xcodeproj" file is located. If not, move the Bridging header file to the project root folder. This way, Xcode can access the bridge file.

  3. Create a project and import the necessary files into the Bridging header.

+12
Sep 14 '16 at 5:27
source share

In Swift 4.1

In your project, you do not have the bridging-Header.h file, but your project has this path. To do this, you need to delete this path ...

Go to the targets file and select "Build Settings", → "Quick Compiler" - "General" and delete the bridging-Header.h file. Follow the screenshots below ... enter image description here

Delete the bridging-Header.h file in the Swift compiler - General

enter image description here

Now you got like this ...

enter image description here

+9
02 Feb '18 at 5:51
source share

For me, it helped to use $(SRCROOT) in front of my Objective-C header loop.

 $(SRCROOT)/swiftLibraries/swiftLibraries-Bridging-Header.h 
+6
Jan 23 '15 at 8:19
source share

Follow these steps:

  • Delete the header file., (Perhaps you are creating manually) and
  • Create a new Swift file in Objective-C Project., (Do not import, create it first)

Perhaps these two things will help solve your problem.

+5
Oct 20 '14 at 11:39
source share

The following worked for me:

  • The Bridging header file should be located in the main root folder of the project, where the ".xcodeproj" file is located. Go to the project directory and drag the title bar to the root directory if it is inside any other folder.
  • Correct spelling errors in title.
  • Clear Derived Data
  • Target → Build Settings → Swift Compiler: General → Add Obj C. Header Name
  • Clean and restart.
+5
Mar 22 '17 at 13:56 on
source share

Manual bridge header file creation

First of all, delete the Bridging header file that Xcode creates. And select your goo project> Build Settings> Keyword Search. Fast compiler - code generation. Click Objective-C Bridging Header, delete this path. Now clean the project.

Now select project> Window in the navigation bar. Select Projects and delete the derived data.

Now create a new file, select Source , and then select the Header file and create your Bridge header file. The file name should be your project name-Bridging-Header.h and then create it

Select goo project> Build Settings> Keyword Search. Fast compiler - code generation. Click on the Objective-C Bridging Header and add a path to this Objective-C Bridging Header, for example projectname-Bridging-Header.h

Now import your classes into the bridge header file and you can easily compile it.

Your bridge header file looks like this when you create the file manually.

+2
Jun 28 '16 at 10:08
source share

What helped me was to manually move the file along the path given in the error message. So:

  1. I deleted the file (moved to the trash)
  2. Moved it from the trash to the path in the error message
  3. Later I also had to clean the project
0
Jan 09 '19 at 14:41
source share