42

I downloaded a project from GitHub, then pod the following files, some of which are written by OBJ-C and I used a bridge header.

pod ‘SnapKit’
pod ‘MJRefresh’
pod ‘Alamofire’
pod ‘Kingfisher’
pod ‘MBProgressHUD’
pod ‘pop’
pod ‘EVReflection’
pod ‘StreamingKit’
pod ‘iCarousel’
pod ‘ReflectionView’

When I run the project with Xcode 9.0 beta 2, but unfortunately the error log as follows :

error: failed to emit precompiled header '/var/folders/kd/4gh0_kxx3jx4thjb_sssmmcw0000gn/T/EvoRadio-Bridging-Header-97bd5f.pch' for bridging header '/Users/ringo/Downloads/EvoRadio-master/EvoRadio/Resources/EvoRadio-Bridging-Header.h'

I have googled, but no such issue.The error means it needs a PCH file? This is my .pch header configuration: enter image description here It can't solve it.

How to make it?

D4ttatraya
  • 3,100
  • 1
  • 24
  • 46
Ringo
  • 855
  • 1
  • 9
  • 19
  • Check out that answer https://stackoverflow.com/a/10621448/4646572 – krlbsk Aug 20 '17 at 07:39
  • 7
    @mrabins This is an iOS programming issue, not java – Ringo Aug 20 '17 at 07:47
  • Seems like a dup of https://stackoverflow.com/questions/10621382/how-do-i-add-a-precompiled-header-file-to-my-ios-project/10621448#10621448. I used the wrong id... sorry. – mrabins Aug 20 '17 at 07:54
  • @bkrl I use the solution you mentioned, but it didn't solve it. Pls. see the new edit with an image. – Ringo Aug 20 '17 at 08:10
  • I think this thread may be useful https://stackoverflow.com/a/24524692/4646572 – krlbsk Aug 20 '17 at 08:24
  • @bkrl I know it, but ' $(SRCROOT)/EvoRadio/Resources/PrefixHeader.pch' equals the attached image in the question description.They are the same. – Ringo Aug 20 '17 at 10:19
  • didn't work for me either. I build fine in debug mode, get the swiftapp-swift.h error on an archive build. – johnrubythecat Dec 11 '18 at 01:59
  • I am getting same error in simulator but working fine in device. I am using Xcode 12.0.1. In Xcode 11 working on simulator also. – Dipak Oct 19 '20 at 08:42

20 Answers20

31

Note this can also happen if your bridging header imports Objective-C code that itself imports your app's Swift module via myproject-Swift.h. The solution is to use forward declarations for your Swift types and import the project Swift module in the .m file.

@class MySwiftClass or...

typedef NS_ENUM(NSInteger, MySwiftEnumType)

MySwiftEnumType is the lowest level name even for classes. So Swift enum MyClass.MySwiftEnumType becomes just MySwiftEnumType

Hari Honor
  • 8,520
  • 6
  • 45
  • 50
  • I'm facing with the same problem. Can you please give me more detail? – Emre Önder Sep 30 '19 at 14:19
  • 3
    Assuming its the same problem, there is a circular reference issue, like can happen with Obj-C Headers. To fix it, in your Obj-C Header file that is referenced the swift class, remove the #import "myproject-Swift.h" (move it to the `.m` file). And create a forward declaration, `@class MySwiftClass`, for the swift class that's referenced in the ObjC class definition – Hari Honor Oct 09 '19 at 14:15
  • 1
    @HariKaramSingh this was it! Thank you very much! Xcode should get error descriptions from stackoverflow :) – anonymous Dec 20 '19 at 09:36
  • I included myclass.h in bridge file, and on myclass.h there was -swift.h. Removing -swift.h from myclass.h import section, the problem disappeared. Thank you :) – Ronaldo Albertini Apr 30 '20 at 14:38
29

I have tried all of the above steps mentioned in the answers but nothing worked for me, the problem was basically with the deployment target version for the project and in the podfile.

In my project deployment target was 10.0 while in my podfile it was 11.0.

Scr1

scr2

sasquatch
  • 6,126
  • 7
  • 39
  • 56
paras gupta
  • 401
  • 5
  • 8
  • this was my issue. So simple! Yet spent hours trying to figure out why it wasn't working. ‍♂️ – Simon Aug 21 '19 at 13:37
  • My pod file has ios 9.0 ver. And build target was 10.0 but the issue still appeared. Changing the build target to 11.0 fixed the problem. – Oleh H Oct 15 '20 at 18:17
22

Make sure you're opening the proper project workspace, otherwise, the Podfile may not have all the resources it needs to compile.

I saw this same error on a project that had been working fine previously.

I discovered that I had accidentally opened the ProjectName.xcodeproj file rather than the ProjectName.xcworkspace file. Opened the xcworkspace file and presto, project was working again!

BAP
  • 974
  • 7
  • 9
21

I also got exact same issue (Xcode9 beta 6) after I added cocoa pods for Encrypted Core Data.
This is my PodFile:

# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
pod 'EncryptedCoreData', :git => 'https://github.com/project-imas/encrypted-core-data.git'

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

  # Pods for Root

  target 'RootTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'RootUITests' do
    inherit! :search_paths
    # Pods for testing
  end

end

Solution:
1 I added $(inherited) non-recursive to Search Path -> Header Search Paths
2 Then added ${PODS_ROOT} recursive to Search Path -> User Header Search Paths
Both the above in my projects' target build settings.

Please have a look at these SO answers:
1 Inherit Header Search Paths
2 Inherit User Search Paths

D4ttatraya
  • 3,100
  • 1
  • 24
  • 46
  • Thanks for your answer,but i have solved it, I removed all the pods and re-pod them again. – Ringo Sep 07 '17 at 01:12
  • 2
    @Ringo Make this an answer and check it as correct so others can benefit from you findings. – dasdom Sep 19 '17 at 07:11
  • 1
    @D4ttatraya: Thank you so much for the answer. It saved my life. Can you please elaborate a little what exactly are those two lines doing? – iPeter Apr 25 '18 at 13:37
14

For me, this problem occurred when I added new build configuration and scheme to the existing project.

The solution was to run pod install on newly created scheme. After that, project was built successfully.

Aliens
  • 927
  • 3
  • 13
  • 23
6

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
  • 370
  • 2
  • 10
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,088
  • 1
  • 10
  • 18
3

In my case;

Under Target/Build Settings/

Product_Name section was different than $(TARGET_NAME)

When I changed it $(TARGET_NAME), it was resolved.

Varol AKSOY
  • 31
  • 1
  • 2
3

XCode can build seccessful in the some target, but the other target can not.
Finally, I found that Header Search Paths is not the same. (Path: Target > Build Settings > Search Paths > Header Search Paths > add item)
I copied & pasted the path from the successful target. I made it. Bravo.

enter image description here

Zgpeace
  • 1,989
  • 15
  • 20
  • Had the same situation with Xcode 12: wasn't the Search Paths though, but VALID_ARCHS flag (which became deprecated with Xcode 12, who knew https://github.com/CocoaPods/CocoaPods/issues/10077), but the idea still stands - go through the build settings line by line and eventually you will find something :) (and perhaps clean up something in a process, that's always useful :) ) – roxanneM Nov 27 '20 at 12:04
3

I had this issue just when compiling for a simulator not for a hardware device. There were two compile error like:

  • error: failed to emit precompiled header 'Bridging-Header-97bd5f.pch' for bridging header 'Bridging-Header.h'
  • Could not find ActionSheetPicker_3_0/ActionSheetPicker.h in Bridging Header (but it was declared there)

After hours of research and try and errors it turned out, that there was no valid architecture set in the project to compile for simulators.

At Project -> Build Settings -> User-Defined -> VALID_ARCHS add the architecture x86_64 to enable compilation for simulators.

karthik
  • 561
  • 3
  • 13
Marcel Hofgesang
  • 553
  • 1
  • 7
  • 27
  • 1
    I swear every other month I end up here and the winner answer is a different one. Today it was this one, thank you. – JaviCasa May 14 '21 at 10:16
2

My experience with this is that Xcode is unable to find header files for pods/frameworks imported in the project.

My Project experience with this: Updating Xcode9.2 - 9.3 where many cocoapods had to be updated due to implicit definitions now unavailable or being outdated.
I had changed the Podfile to now include 'use_frameworks!'. Following this and after dealing with other compile issues I found the error you are experiencing. I believe adding 'use_frameworks! was preventing some pods with support prior to iOS 8 from compiling correctly. Steps I took to correct this issue:

  1. I tried deleting the Pods/ directory using cocoa pod deintegrate
  2. I then open project with Xcode and cleaned the build folder and the project. (delete content within derived data folder)
  3. I then pod install again but the issue persisted.

  4. Ultimately I removed the use_frameworks line in Podfile and then repeated steps 1-3 and the project was now able to find the missing header files and the issue never presented it self again.

Randoramma
  • 113
  • 8
2

For my case I had a typo in folder name "Supporing FIles" instead of "Supporting Files".

Genki
  • 2,659
  • 1
  • 25
  • 39
1

Deleting Podfile.lock and re-running pod install fixed this for me.

Zack Shapiro
  • 5,202
  • 14
  • 65
  • 121
1

There are so many reasons and things can do, like:

The only one works for me is the accepted answer in Xcode 9 - failed to emit precompiled header.

platform :ios, '11.0' in podfile should match the target in the project

Krzysztof Romanowski
  • 1,956
  • 2
  • 22
  • 28
Allen
  • 2,073
  • 1
  • 23
  • 25
0

I had same scenario, make sure for the file A that you have included in YourProjectName-Bridging-Header.h

  • if it uses some other class(s), then those other classes are also included before that File A
Muhammad Waqas
  • 784
  • 2
  • 8
  • 21
0

In my case, I was building with the wrong scheme (Top-Left menu).

atulkhatri
  • 9,359
  • 3
  • 45
  • 79
0

I also suffered from this after I updated new Xcode. After several hours of investigation, i found that if you have multiple targets, you now have to add more targets in pod file in Xcode 10. So your code should be like this:

platform :ios, '9.0'

target 'EvoRadio' do

pod ‘SnapKit’
pod ‘MJRefresh’
pod ‘Alamofire’
pod ‘Kingfisher’
pod ‘MBProgressHUD’
pod ‘pop’
pod ‘EVReflection’
pod ‘StreamingKit’
pod ‘iCarousel’
pod ‘ReflectionView’

target 'EvoRadio2ndtarget'   # add your second target

end

I found that in Xcode 9 you don't need to add, but in Xcode 10 you need to add this. Hope this helps.

Richter
  • 104
  • 1
  • 5
0

For Xcode 11 I had an issue with the "Security.framework". I removed this dependency, then re added it. Ultimately fixed the other problems

MobileMon
  • 7,249
  • 4
  • 46
  • 66
0

I got this error after renaming the existing Xcode project configuration in which I had another Xcode project imported.

To fix it, you have to rename the same configuration in the imported project as well.

Viktor Malyi
  • 1,913
  • 2
  • 21
  • 35
0

Since I have been stuck in this issue for 2 working days , I would like to share my issue for you because may be future searchers are facing my problem

I was getting the mentioned error when running with command line , and I found that the command I was writing was for running .xcodeproj ,, but to run a .xcworkspace you have to write the following command

xcodebuild -workspace PROJECTNAME.xcworkspace clean archive -archivePath build/PROJECTNAME -scheme SCHEMENAME

el3ankaboot
  • 145
  • 1
  • 9