Xcode 8 Beta 3 Use Legacy Swift issue
Asked Answered
M

20

202

I have an Objective-C project in Xcode 8 Beta 3. Since updating, whenever I try to build I receive 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.

Has anyone encountered this? Since it's an Objective-C project there's no build setting to configure Swift. I have also made sure none of the project dependencies or CocoaPods are using Swift. The only solution I have is to use Beta 2. Any ideas how I might fix this issue?

I should also mention I'm running OSX 10.12 Beta 2.

Mahayana answered 18/7, 2016 at 21:14 Comment(1)
I am also having this issue...Rootless
M
34

I have been ignoring this problem for a while now and just working on other stuff in the meantime - I finally found the solution to my problem.

Since my project is Objective-C I figured maybe one of the Pods I am using was using Swift, I checked each Pod and none of them were.

The final solution was that my Core Data model was set to generate code in Swift even though I have been manually generating them in the File > New > NSManagedObjectSubclass menu. All I had to do was switch it to Objective-C.

screenshot

Mahayana answered 26/7, 2016 at 18:48 Comment(2)
How did you find this? Xcode says nothing about this. You saved me.Shaman
Indeed my solution and my saviour. Thanks! Stupid how Apple makes Coredata models automatically 'Swifty' when the whole App is objective-c....Threesome
T
364

If you are using CocoaPods and want it to be fixed automatically every time you are doing a pod install, then you can add these lines to the end of your Podfile:

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

EDIT: This problem is now fixed if you use CocoaPods v1.1.1 or later. Don't forget to remove the ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES setting from your main project targets.

Trashy answered 19/7, 2016 at 19:12 Comment(13)
Any ideas for a fix using Carthage?Significant
If you are trying to use 2.3 in your codebase for the time being, use 2.3 instead of 3.0 Great solution! This effectively makes the "Use Legacy Swift Language Version" to No (or if you change it to 2.3 it's Yes). The benefit of this option though is every time you pod install it sets that setting automatically! Awesome. I see SWIFT_VERSION gets set on Obj-C projects as well. I assume there aren't any adverse affects?Retardation
This is great, but it's quite disturbing that without a Ruby expert on StackOverflow, thousands and millions of projects are SOL. I manually changed the Xcode setting SWIFT_VERSION to 2.3 in every module and in the Pod project, using Build Settings, and it didn't work, but this did. Meaning hidden disturbing magic. I hate that.Gripe
@TommieC. if you need Swift 2.3 and use Xcode 8 you should change the TOOLCHAINS. So carthage: TOOLCHAINS=com.apple.dt.toolchain.Swift_2_3 carthage update --platform iOSVerb
Note: it is not necessary to add it to the end of the Podfile, since you are using post_installCommodious
I literally logged in just to give you props on thisCogitative
I have a Obj-C project with Charts(in Swift), AfNetworking and some other Obj-C pods. I used above script in my pod file. All errors/warning related to swift are gone but now my project can't find AFNetwoking framework.Dicarlo
@Trashy not my question but this is exactly my case. #39622952Dicarlo
I love how this is not documented anywhere except Stack Overflow. Also, even on CocoaPods 1.1.1 and XCode 8.1 it remains an essential step.Superpatriot
Why is this needed in the first place, is there is no way to do it inside Xcode settings?Ianteen
@Mr.Bista The approved solution https://mcmap.net/q/127112/-xcode-8-beta-3-use-legacy-swift-issue makes it work from Xcode settings. But you might have to do it with every single Pod repo that you have every time you are doing a pod install / update. This solution makes things faster. You can also update your Cocoapods version now: it should also fix this issue.Trashy
@GlennSchmidt I am on CocoaPods 1.1.1 and Xcode 8.1 and I removed the code above from my Podfile for some weeks now. Everything works back to normal.Trashy
I'm on CocoaPods 1.2.1 but for some reason I got the same error until I added the bit above into my Podfile. Anybody know why? I'm in Xcode 8.3.3 and building my target for iOS 9.Ideography
R
119

I just found a way to fix it.

Go to the Build settings of the project or library and set the Swift Compiler Version attribute "Use Legacy Swift Language Version" from Unspecified to Yes or NO.

enter image description here

Rootless answered 19/7, 2016 at 8:51 Comment(6)
I don't see this option in my Objective-C projectMahayana
Do you have any Swift project libraries in your Obj-C project?Rootless
If you are using swift and cocoapods, the command above in cocoapods effectively does this. If you don't want to have to change this every time you pod install I recommend using @Trashy 's answer above.Retardation
Now my error is Swift Compiler Error in a self classGesture
In my case, click "Pods.xcodeproj" choose "ReactiveCocoa" → “Use Legacy Swift Language Version”:change unspecified to YES or NODina
This option is no longer available.Advertent
M
34

I have been ignoring this problem for a while now and just working on other stuff in the meantime - I finally found the solution to my problem.

Since my project is Objective-C I figured maybe one of the Pods I am using was using Swift, I checked each Pod and none of them were.

The final solution was that my Core Data model was set to generate code in Swift even though I have been manually generating them in the File > New > NSManagedObjectSubclass menu. All I had to do was switch it to Objective-C.

screenshot

Mahayana answered 26/7, 2016 at 18:48 Comment(2)
How did you find this? Xcode says nothing about this. You saved me.Shaman
Indeed my solution and my saviour. Thanks! Stupid how Apple makes Coredata models automatically 'Swifty' when the whole App is objective-c....Threesome
M
18

This issue is also visible in Xcode-8.1 . When we add new Target like Extension or Widget and Third party library is integrated in new target with the help of cocopods. After Pod install . We can face same error as above .

Change the Use Legacy Swift Language Version in every Library Build Setting to

No.

enter image description here

Money answered 8/11, 2016 at 9:0 Comment(4)
In my case setting Use Legacy Swift Language Version to Yes resolved the issue.Bandsman
Ensure that for each lib having this issue that you either set Yes or No.. in my case No workedPeplos
This worked for me. Please make sure you do the same for the Test target as wellGagger
@Gagger :- We have to cross check in all the target. Thanks in pointing again.Money
M
9

If you are using Xcode 8 or later

  1. Go to Build Settings
  2. Find use legacy swift language version
  3. Yes - Swift 2.3
  4. No - Swift 3.0 enter image description here
Mcquade answered 4/2, 2017 at 10:11 Comment(0)
R
5

Add below code in end of the podfile.

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['SWIFT_VERSION'] = '3.0'
    end
  end
end
Rectrix answered 7/10, 2016 at 4:56 Comment(0)
O
4

I'm working on a project which has mixed objective-c and swift code I previously used swift version 2.3 and after upgrading to swift 3 I was unable to build the project. Xcode complained with the mentioned error message.

Apparently, there was still some outdated Swift version specified in my project.pbxproj file. There was swift 3.0.1 specified:

SWIFT_VERSION = 3.0.1;

Whereas, I already had 3.0.2 installed:

$ xcrun swift -version
Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)
Target: x86_64-apple-macosx10.9

Sooo, I fixed it by changing the Swift version in the project-pbxproj file to:

SWIFT_VERSION = 3.0;

Seems the patch level version specifier was too specific.

Osteomyelitis answered 16/12, 2016 at 10:12 Comment(0)
M
4

In my case I have Just do the Following things

Choose project Target=>Go to Build setting=>Search for “Swift Language Version” =>give Value the current Swift version

Thats all It has fixed my Issue

Follow This Image

Menam answered 14/8, 2017 at 11:59 Comment(0)
P
4

I got the same error. I tried for searching "Use Legacy Swift Language Version", but not found. I am using Xcode 8.3.3 After surfing too much and working around i found this solution, and this worked for me.enter image description here

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.)
Plasty answered 24/10, 2017 at 7:23 Comment(0)
E
3

set "Use Legacy Swift Language Version" to "YES" if you using a old version of swift in your project or any swift 3rd party. "No" if your project uptodate to current swift version. if you don't configure your swift version , after every update and Install, Pod framework need to specify this.

Enzymolysis answered 22/9, 2016 at 7:50 Comment(0)
L
2

I actually had to do a search for "Legacy Swift" to be able to change it from unspecified to "Yes" When I simply scrolled down to the section described above, I was not able to change it. I hope this will help someone.

Leviticus answered 11/10, 2016 at 21:46 Comment(0)
L
2

My project is written in Swift. I got that same error with fastlane. What happened was my Xcode auto-updated so I had to update my project to Swift 3.0. Got a ton of errors. Fixing and debugging was taking too much time and it was not worth it at that moment so I decided to install an older version of Xcode. Reverted my code to 2.3. Then fastlane beta wasn't working anymore. Turns out, I needed to set the Command Line Tool to 7.3. enter image description here

Lattimer answered 10/11, 2016 at 4:5 Comment(0)
M
1

If you change ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES to NO still not work, it is because the xcode issue, not your problem. Doing the follow steps:

1.Change ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES property to be YES on the warning target

2.then it will show an warning on left bar which recommend you change to swift 3.0

3.then change back to NO. Rebuild the project, the xcode finally detect your change to NO!

Problem solved in this case!

Mitchel answered 24/1, 2017 at 5:13 Comment(0)
H
1

I was having this same issue and solved it by doing the following:

In Project > Build Settings:

Always Embed Swift Standard Libraries = $(inherited) Use Legacy Swift Language Version = YES

Then in my Podfile:

config.build_settings['SWIFT_VERSION'] = '3.0'

Using these three settings removed all warnings and allowed me to compile properly.

The most obscure and what actually got progress for compiling was changing the SWIFT_VERSION in the Podfile from 3 to 3.0 as suggested here.

Higley answered 30/1, 2017 at 16:19 Comment(0)
B
1

From XCode 8 onwards, you can use swift 2.3 even though XCode 8 uses swift 3.x as default swift version. To use swift 2.3, just turn on flag Use Legacy Swift Language Version to YES from Build Setting, then XCode will use Swift 2.3 for that project target.

Blastogenesis answered 1/2, 2017 at 11:27 Comment(0)
E
1

Before trying complicated solutions, here is a basic check you need to do if you are new to Cocoapods and you are having this issue.

You might need to:

  • Open your Podfile again
  • Check that the line for platform is not commented out with a '#'. It should finally look like something like :

platform :ios, '10.1' # Put the right version and no #platform here use_frameworks! # For swift pod "MyPod" # Your mean pod :)

  • Save your Podfile, Close Xcode, and Run pod install again
  • Open your project.xcworkspace

Maybe it's just that.

If not, you can go above ;-)

Extinction answered 2/3, 2017 at 12:38 Comment(0)
C
1

I had this same problem after updating to xcode 8.3.2 but the option "Use Legacy Swift Language" was gone. This seems to be the option to change now: Swift Lang Version

Used this fix with Alamofire and other libs and all works ok.

Campman answered 24/4, 2017 at 13:48 Comment(0)
W
1

Go to Project Build Setting for project and Target do below two.

ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES
And
Swift Compiler - Version  = Swift 3

Change to latest Swift 3.

Error resolved.

If it's resolved your error fix, please like it.

Weaponry answered 25/4, 2017 at 6:59 Comment(0)
M
1

In Xcode 9 beta. Go to Project Settings, Build Settings, search for Swift Language Version. In Xcode 9 you must specify if you are using Swift 3.2 or Swift 4.

Maleate answered 6/6, 2017 at 15:58 Comment(1)
I had a project in 9.0b where setting both the project and the target to Swift 4 continued to produce the error, setting both to Swift 3.2 removed it, and setting both back to Swift 4 now is fine, so one may do everything right and still get an error.Alcohol
H
0

Just need to check the following settings

File -> Workspace setting ->

1 - Check "Don't show a diagnostic issue about build system deprecation"

2 - set Build System to Legacy Build System (Shared Workspace)

3 - set Build System to Legacy Build System (Pre-User Workspace)

Haberman answered 18/8, 2022 at 9:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.