Migration to Swift 4 from Swift 3.2 giving "failed to import bridging header " error

Viewed 16117

As apple has released Xcode 9 beta version with Swift 4.0 support. I have been trying to upgrade my code to Swift 4.0 from Swift 3.2. But it keeps giving me failed to import bridging header error whereas my project build successfully.

Xcode error detail:

Convert to Current Swift Syntax Failed

Please ensure that all selected targets build successfully with the currently configured Swift version before attempting a migration.

Has anybody faced the similar error while upgrading code base to swift 4.

7 Answers

for us what worked was to remove the UnitTest and UITests

Tap on your project and then "Right Click" -> Remove the two dependencies

Hope it helps

Probably at least one of the objective c classes you put in your bridging header file is not compiling - comment out all your entries in the bridging header file, then compile - it should be able to import the bridging header now, but of course generate lots of errors because of classes not found. Now uncomment the lines one by one to find out which ones are causing the import to fail, and then fix those files.

After changing the Swift Language Version in my Project's build settings and in all the targets I had to alter this function declaration in AppDelegate.swift to:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true }

All of my code is in Swift 5, except for one of my Pods which hasn't been updated in a few years. That pod uses Swift 4.

This error happened for me when I added a new Swift5 pod.

So, All I needed to do was:

  1. Change Affected Pod's Swift version to match the rest of the project

enter image description here

  1. Clean project
Related