51

I have a project in Objective-C as well as in swift by taking MyProjectName-Bridging-Header.h and i also configured the Objective-C Bridging Header. Also i have added 'MyprojectName-Swift.h' in .pch file.

This works fine on xcode 8.2 but when i build my project from xcode 9 i am getting the below error.

failed to emit precompiled header '/Library/Developer/Xcode/DerivedData/MyprojectName-lajanjvhqjnfjksdsndsfkads/Build/Intermediates.noindex/PrecompiledHeaders/MyprojectName-Bridging-Header-swift_44AHJm3Z96qu-clang_2BIMGQVXGEZ09.pch' for bridging header '/Documents/MyProjectLocaiton/FoneApp-Bridging-Header.h'

Please help me out from this. Thanks!

Shubham
  • 1,230
  • 2
  • 12
  • 26

12 Answers12

28

I found out that I accidentally opened the ProjectName.xcodeproj file rather than the ProjectName.xcworkspace file.

Open the xcworkspace file, project will start working again!

nikdange_me
  • 2,949
  • 2
  • 16
  • 24
24

Read this if you using cocoapods in project. I just update deployment target to iOS 10 or 11 in my case after updating pods and xcode make first build success. So problem was inside podfile where I had line

platform :ios, '11.0'

and my deployment target in project was 9.0 after I change my podfile to platform to

platform :ios, '9.0'

project was fixed.

Ivan Besarab
  • 990
  • 7
  • 12
  • 1
    Thanks! I had this issue while merging branches, my podfile was set to platform :ios, '10.3' while my xcode minimum deployment target was still at 10.0, you need to change it to 10.3 in xcode THEN run pod install – xGoPox Feb 07 '19 at 12:19
15

Also make sure your import of "ProductModuleName-Swift.h" is in your .m file, and not your .h file.

Elijah
  • 8,381
  • 2
  • 55
  • 49
12

Finally i got the solution of this issue. In my project the Prefix Header path is not clearly defined. Earlier the path was

$(SRCROOT)/MyPrefixHeaderFile.pch

MyPrefixHeaderFile.pch is in another folder inside the project folder, So i update the Prefix Header path to

$(SRCROOT)/FolderName/MyPrefixHeaderFile.pch

Shubham
  • 1,230
  • 2
  • 12
  • 26
10

Maybe you created a new target, but forgot to add this to your Podfile:

target 'Pistachio-rrzcpjs' do

end
ZGski
  • 2,398
  • 1
  • 21
  • 34
Li Yakun
  • 117
  • 1
  • 2
7

You can try this solution. I have solved the same problem by this way.

Product > Scheme > Edit Scheme > Select "Build" on Left Menu > Find implicit dependencies

Under the build tab, check 'Find implicit dependencies':

Find implicit dependencies

Then make a clean and build again.

Okan
  • 410
  • 4
  • 10
7

When you are getting this error in terminal upon running the xcodebuild command, do make sure you pass -workspace YourWorkspace.xcworkspace

Anand
  • 216
  • 3
  • 10
4

in my point of view I solved simply switch the order of import statements and build works fine.

Alessio Campanelli
  • 970
  • 11
  • 19
3

In my case I had the same compiler error with additional errors like "Unknown type" in one of my project files, So I just added this to the problematic file, and it solved it instantly.

#import <UIKit/UIKit.h>

Benzi Heler
  • 1,138
  • 1
  • 10
  • 18
3

Adding my very own situation to the loop.

In my bridging header file, le'Ts say I added an import

#import "File.h"

Inside the File.h header file, there was a type referenced from an import that was inside the Prefix.pch, had to add the missing #import in my File.h

2

@Li Yakun This is the solution if you have more then one target in project, every new target in podfile must have:

target 'NEWTARGET' do
    # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
    use_frameworks!

    # Pods for MAINTARGET
    shared_pods
end
clopex
  • 459
  • 6
  • 11
0

Also if you have multiple targets, be aware to include your #imports in every file.

Gabriel Oliva
  • 143
  • 1
  • 11