Search code examples
iosswiftobjective-cxcodebridging-header

Adding an Objective-C file into a Swift project breaks compilation with "Build input file cannot be found" error


I have an existing Swift project (UIKit), Xcode 14.2. I'm trying to add Objective-C code to it, creating .m and .h files. The moment I try to add it, Xcode asks me to create the bridging header (an empty one) which is created and registered in build settings correctly.

My .h file:

#ifndef TestObjC2_h
#define TestObjC2_h


#endif /* TestObjC2_h */

My .m file:

#import <Foundation/Foundation.h>
#import "TestObjC2.h"

My bringing header file is empty.

When I try to build it, getting the following error:

error: Build input file cannot be found: '/Users/.../mycoolproject/OptimizationProfiles/mycoolproject.profdata'. Did you forget to declare this file as an output of a script phase or custom build rule which produces it? (in target 'mycoolproject' from project 'mycoolproject')

Creating the same files in a new Swift project has no issue and compiles fine.

What did I miss?


Solution

  • The setting CLANG_USE_OPTIMIZATION_PROFILE was on and disabling it (set to NO) fixes the issue.

    In a new project this settings by default is set to NO.