An Objective-C file cannot find the generated Swift header
'MyApp-Swift.h' file not foundShort 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.
Fix it fast
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"2Match what you see, then jump to its fix
- 1
The 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
The 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
The 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
- 1
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 Name2Fix
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
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 Module2Fix
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
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
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
UserDefaults logs 'Failed to read values in CFPrefsPlistSource' for an app group
Settings saved by the app are not visible to its extension, widget or sibling app that share the group
This log comes from the preferences system when UserDefaults is opened for an app group's suite.
3 causes, each with a fixMobile apps
iOS app crashes: Google Maps SDK must be initialized via provideAPIKey
Google Maps SDK for iOS must be initialized via [GMSServices provideAPIKey:...] prior to use
The Maps SDK throws this when a Maps object is created before GMSServices.provideAPIKey has run.
3 causes, each with a fixMobile apps
UIKit app crashes because it cannot find the storyboard
Could not find a storyboard named 'Main' in bundle NSBundle
UIStoryboard throws this exception when no storyboard file with that name exists in the bundle it searches.
3 causes, each with a fixMobile apps
Firebase on iOS asks for the FCM token before APNs has given one
Be sure to re-retrieve the FCM token once the APNS device token is set.
The Firebase Messaging SDK needs the APNs device token from iOS before it hands out an FCM token.
3 causes, each with a fixMobile apps
A test push from the Firebase console never shows up on the iPhone
didReceiveRegistrationToken prints a token, yet no notification arrives
When a console message is accepted but the iPhone stays silent, the break is between Firebase and APNs or inside the app.
4 causes, each with a fixMobile 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