xcode 8 swift update with error “Use Legacy Swift

2019-03-23 07:58发布

问题:

When i opened my project into Xcode 8 then I got the following error

Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly

referring to a similar post on StackOverflow , Use Legacy Swift Language Version YES/NO . But it's not working for me either by doing YES or No value ?

Please help.

I have checked Use Legacy Swift Language Version to options YES/NO please check attached screenshot

回答1:

Add this to your pod-file:

# Uncomment this line to define a global platform for your project
platform :ios, '9.0'
# Uncomment this line if you're using Swift
use_frameworks!

target 'yourappname' do

pod 'yourpodlists'

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['SWIFT_VERSION'] = '2.3'  ## or '3.0'
        end
    end
end
end

Run pod-install again. Clean your project with cdm + alt + shift + k. Clean again using cmd + shift + k. Restart Xcode. Build. Now it should work.

If you're not using cocoapods, you should be able to fix this issue by setting the Compiler Version attribute Use Legacy Swift Language Version from unspecified to Yes or No.

Build settings of the project or library ->



回答2:

try converting swift code to swift3 or swift 2.3. edit -> convert -> to current swift-> select swift 3 or swift 2.3. This will works.



回答3:

I am using Xcode 8.3.3 After surfing too much and working around i found this solution, and this worked for me.

Here are the steps.
1=> select your target from Xcode
2=> go to build setting
3=> search for "Swift Language Version"
4=> change it to swift 3. (or accordingly.)


回答4:

If you're not using pods just add this to your Info.plist - I'm on 2.3

as the option wasn't listed in build settings.



回答5:

As reference to this, This is what I've concluded (for Xcode 8) :

  1. If your code is in swift version = 2.3 then you just need to set Use Legacy Swift Language Version to YES in build setting and you will good to go.
  2. If your code is in swift version < 2.3 then :

    i) convert your code to swift 2.3 and Set 'Use Legacy Swift Language Version = YES'

    OR

    ii) convert your code to latest swift version (might be 3.0) and Set 'Use Legacy Swift Language Version = NO'

In my case, I've used external library which was in swift 2.2 causing errors in Xcode 8.0, so I replace the same library with swift version 2.3 and used above solution 2.i). Now everything is fine.

Hope this help someone who are seeking the solution to this problem.