Skip to content

How to Fix iOS Swift-Objective-C Bridging Header Error

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about How to Fix iOS Swift. We cover key concepts, practical examples, and best practices.

The Problem

You add Objective-C code to a Swift project and get:

'MyObjCClass.h' file not found

Or:

Failed to import bridging header
'/path/to/Project/Project-Bridging-Header.h'

Xcode cannot find or parse the bridging header file that connects Objective-C to Swift.

Quick Fix

Step 1: Create the bridging header

Xcode prompts to create a bridging header when you add the first .m file to a Swift project. If you declined, create it manually:

File > New > File > Header File > Name it YourProject-Bridging-Header.h.

Step 2: Set the bridging header path in build settings

Build Settings > Objective-C Bridging Header:

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

The path is relative to $(SRCROOT) (the project folder). Use $(SRCROOT)/Target/Bridging-Header.h if the file is in a subfolder.

Step 3: Import Objective-C headers in the bridging header

// YourProject-Bridging-Header.h

#import "MyObjCClass.h"
#import "SomeOldLibrary.h"

Do not import UIKit or Foundation in the bridging header -- those must be imported in the individual .m files.

Step 4: Verify target membership

Select the bridging header file in the Project Navigator. In the File Inspector, verify it is a member of your app target. Without target membership, the compiler cannot find it.

Step 5: Check the Objective-C file's target membership

Every .m file that the bridging header references must also be a member of the same target.

Step 6: Use @class forward declarations

// Instead of importing everything, forward-declare where possible
@class MyObjCClass;

// Then in the bridging header, import only what Swift needs to see
#import "MyObjCClass.h"

Step 7: Import Swift code in Objective-C

Xcode generates a -Swift.h header automatically:

// In an Objective-C .m file
#import "YourProject-Swift.h"

This header exposes Swift classes marked with @objc to Objective-C.

Step 8: Mark Swift classes as @objc

@objc class MySwiftClass: NSObject {
    @objc func doSomething() {
        print("Hello from Swift")
    }
}

Only @objc members are visible in the generated -Swift.h header.

Prevention

  • Create the bridging header when Xcode first prompts you.
  • Keep the bridging header clean -- import only what Swift needs.
  • Use @objc and @objcMembers deliberately for Swift-to-ObjC exposure.

Common Mistakes with swigift bridge

  1. Forgetting deriving (Show, Eq) on custom data types needed for debugging
  2. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  3. Using head and tail instead of pattern matching, causing runtime errors on empty lists

These mistakes appear frequently in real-world IOS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does the bridging header fail with "file not found"?

The path in Build Settings is wrong relative to $(SRCROOT), or the file is not a member of the target. Verify both.

Can I have multiple bridging headers?

No. Xcode supports only one bridging header per target. Import all Objective-C headers into that single file.

Do I need a bridging header if I use only Swift?

No. The bridging header is required only when mixing Objective-C code into a Swift project. Pure Swift projects do not need it.

DodaTech Tool Reference

Doda Browser's Source Inspector can verify bridging header syntax and path correctness before building, reducing trial-and-error during setup.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro