Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

An Objective-C file cannot find the generated Swift header

Error'MyApp-Swift.h' file not found

Short answer

Xcode generates the header from the product module name plus -Swift.h. File not found usually means the name in your import is wrong, a framework target is missing the Defines Module setting or the framework-qualified import form, or the import sits in a header that should use a forward declaration instead.

  • Applies to Xcode 26, Swift 6, Objective-C
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Read the module name Xcode actually uses. The header is named after it, not after the folder or the project.

    # Xcode: select the target > Build Settings > search "Product Module Name" and "Defines Module"
  2. 2Match what you see, then jump to its fix

    1. 1The product name has spaces, dashes or a leading digit, or the project was renamedThe import uses a name that is not the product module nameFix
    2. 2The Swift and Objective-C code live in a framework, or you import the framework from another targetA framework target does not define a module, or the import form is wrongFix
    3. 3The import is in a .h file, and the build reports a cyclical reference or the header cannot be foundThe generated header is imported in an Objective-C headerFix

What does the error look like?

  • 'MyApp-Swift.h' file not found
  • #import "MyApp-Swift.h" fails with: file not found

Cause 1 of 3

The import uses a name that is not the product module name

1Check

The header is the product module name followed by -Swift.h. By default the module name is the product name with nonalphanumeric characters replaced by underscores, and a leading digit is replaced by an underscore too.

# Xcode: target > Build Settings > Packaging > Product Module Name

2Fix

Import the header using exactly the Product Module Name shown in Build Settings, or set a custom name in the Product Module Name build setting.

// MyObjcClass.m  (PRODUCT_MODULE_NAME = My_App)
#import "My_App-Swift.h"

3Verify

Clean the build folder and build again.

# Xcode: Product > Clean Build Folder, then Product > Build (Cmd+B)

Confirmed by developer.apple.com

Did this fix it?

Cause 2 of 3

A framework target does not define a module, or the import form is wrong

1Check

For a framework target, Defines Module under Packaging must be Yes. Code in the same framework imports the generated header inside .m files.

# Xcode: framework target > Build Settings > Packaging > Defines Module

2Fix

Set Defines Module to Yes for the framework target and use the framework-qualified form in the Objective-C file.

#import <MyFramework/MyFramework-Swift.h>

3Verify

Build the framework target and then the app.

# Xcode: Product > Clean Build Folder, then Product > Build (Cmd+B)

Confirmed by developer.apple.com

Did this fix it?

Cause 3 of 3

The generated header is imported in an Objective-C header

1Check

Importing the generated header from a header creates a cyclical reference when the declarations refer to Swift types from the same target.

grep -rn -- "-Swift.h" --include=*.h .

2Fix

Use a forward declaration in the .h file and import the generated header in the matching .m file.

// MyObjcClass.h
@class MySwiftClass;
@interface MyObjcClass : NSObject
- (MySwiftClass *)makeSwiftObject;
@end

// MyObjcClass.m
#import "MyApp-Swift.h"

3Verify

Build again. The cycle and the missing header message are gone.

# Xcode: Product > Clean Build Folder, then Product > Build (Cmd+B)

Confirmed by developer.apple.com

Did this fix it?

How do I stop it coming back?

  • Pick a product name made of letters and digits only, not starting with a digit, so the module name matches it.
  • Import the generated header only in .m files, and forward-declare Swift classes in headers.
  • In a framework target, declare the Swift types you need from Objective-C as public or open, because only those appear in the generated header.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Mobile apps

InstanceID token() no longer works in a Swift Firebase app

Instance ID calls fail to compile after upgrading Firebase to 8.0.0 or later

Firebase removed the Instance ID dependency from Messaging in 8.0.0, so InstanceID.instanceID() calls no longer belong in a current app.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.