19

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.

Community
  • 1
  • 1
Varun Mehta
  • 1,733
  • 3
  • 18
  • 39
  • 3
    I deleted the `NAME.xcworkspace ` and regenerate using 'pod install' then it works. – JZAU Aug 30 '17 at 03:12

7 Answers7

9

I had the similar problem in one of my projects and how I solved this is next:

I figured out that CocoaPods are the problem.

  1. I removed CocoaPods from my project (if you don't know how to do that check this How to remove CocoaPods from a project?)

  2. Don't forget If you have unit & ui tests you have to repeat 4th step from the link above on them as well.

  3. Upgrade your code base to Swift 4

  4. Install pods again and you are done.

Hope it helps :)

swiftBoy
  • 35,607
  • 26
  • 136
  • 135
Tino Krželj
  • 91
  • 1
  • 4
4

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

tsik
  • 609
  • 8
  • 10
1

For me, my migration from 3.2 to 4.0 failed, then I always get this error message when I try to Edit > Convert > To Current Swift Syntax...

My Fix is simple, set the project setting's swift version from 4.0 back to 3.2 or whichever version you were using.

This is because although the first migration has failed, Xcode has changed the swift version to 4.0 in your project settings.

Ben Kax
  • 446
  • 4
  • 3
0

Make sure that all the targets compile including the tests. delete NAME.xcworkspace once Cocoapods are removed from the project

This solved it for me.

0

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.

TheEye
  • 9,280
  • 2
  • 42
  • 58
0

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 }

nyxee
  • 2,773
  • 26
  • 22
0

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
grantespo
  • 2,233
  • 2
  • 24
  • 62