Xcode 10 convert to Swift 4.2 fails - ios

I am getting this error trying to migrate to Swift 4.2 using the Xcode provided conversion tool. How do I fix it? The code builds fine otherwise.

Do you have any libraries in your project? I think you are trying to covert your project with dependencies and there are problems in them with new swift version. Try to uncheck all dependencies except your project and convert to new version of Swift

I had similar problem, solved it by
1- Change swift lang version in build setting of all app and test targets to 4.2
2- build app, errors will happen like UIControlState renamed to UIControl.state
3- fix all of the build errors
4- I updated all recommended settings by xcode
5- then I asked xcode to convert to swift4.2

It's always a good idea to upgrade all dependencies (e.g. via Cocoapods) to its latest version that support Swift 4.2. In my case, I also need to manually change the Swift Language Version build settings for a pod library from Swift 4 to Swift 4.2 as that lib uses some APIs in 4.2 only.

I have problem too. I find solution to fix this problem in web
https://ericasadun.com/2018/09/13/converting-projects-by-hand-to-4-2/
First
You try delete pod in pod file and install pod again and pod update in your folder project in command then conversion to Swift 4.2.
if it's not work do this in second.
Second
you try follow do this picture in build setting project or try follow do in link web.

As described here,
There may have been issues with processing the targets that will
negatively impact the migration process. Switch to the Report
Navigator and select the Convert entry that was added; this is the
conversion build log. Check the log for errors that may have showed
up.
If you see errors about not being able to code-sign the target, try
disabling code-signing from the build settings of the target. If you
see other errors, please file a bug report and include the details.
You are strongly encouraged to attach a project that illustrates the
faulty migration if possible.

Related

Xcode 9 Swift Language Version (SWIFT_VERSION)

I've recently updated xcode to version 9. Before that in Xcode 8.x whenever I use to do pod update it shows me an update code to convert the code to Swift 3 and doing that solve the errors. But now it is giving me this error:
The “Swift Language Version” (SWIFT_VERSION) build setting must be set
to a supported value for targets which use Swift. This setting can be
set in the build settings editor.
For this error I've tried Build Settings > Swift Language Version and it was Swift 3.2
But as the update call has re-installed some of the pods like Alamofire and it says to install Xcode 8.x to convert the code to Swift 3 so do I need to install an additional version with the latest Xcode? If yes, then how can I install Xcode 8 with Xcode 9?
Answer to your question:
You can download Xcode 8.x from Apple Download Portal or Download Xcode 8.3.3 (or see: Where to download older version of Xcode), if you've premium developer account (apple id). You can install & work with both Xcode 9 and Xcode 8.x in single (mac) system. (Make sure you've Command Line Tools supporting both version of Xcode, to work with terminal (see: How to install 'Command Line Tool'))
Hint: How to migrate your code Xcode 9 compatible Swift versions (Swift 3.2 or 4)
Xcode 9 allows conversion/migration from Swift 3.0 to Swift 3.2/4.0 only. So if current version of Swift language of your project is below 3.0 then you must migrate your code in Swift 3 compatible version Using Xcode 8.x.
This is common error message that Xcode 9 shows if it identifies Swift language below 3.0, during migration.
Swift 3.2 is supported by Xcode 9 & Xcode 8 both.
Project ► (Select Your Project Target) ► Build Settings ► (Type 'swift' in Searchbar) Swift Compiler Language ► Swift Language Version ► Click on Language list to open it.
Convert your source code from Swift 2.0 to 3.2 using Xcode 8 and then continue with Xcode 9 (Swift 3.2 or 4).
For easier migration of your code, follow these steps: (it will help you to convert into latest version of swift supported by your Xcode Tool)
Xcode: Menus: Edit ▶ Covert ▶ To Current Swift Syntax
For Objective C Projects created using Xcode 8 and now opening in Xcode 9, it is showing the same error as mentioned in the question.
To fix that, Press the + button in Build Settings and select Add User-Defined Setting as shown in the image below
Then in the new row created add SWIFT_VERSION as key and 3.2 as value like below.
It will fix the error for objective c projects.
I just got this after creating a new Objective-C project in Xcode 10, after I added a Core Data model file to the project.
I found two ways to fix this:
The Easy Way: Open the Core Data model's File Inspector (⌥⌘-1) and change the language from Swift to Objective-C
Longer and more dangerous method
The model contains a "contents" file with this line:
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="14460.32" systemVersion="17G5019" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
In there is a sourceLanguage="Swift" entry. Change it to sourceLanguage="Objective-C" and the error goes away.
To find the "contents" file, right click on the .xcdatamodeld in Xcode and do "Show in Finder". Right-click on the actual (Finder) file and do "Show Package Contents"
Also: Changing the model's language will stop Xcode from generating managed object subclass files in Swift.
This can happen when you added Core Data to an existing project.
Check the:
<Name>/<Name>.xcdatamodeld/<Name>.xcdatamodel/contents file.
This file contains an entry "sourceLanguage" that (by default) might have been set to "Swift". Change it to "Objective-C".
I just click on latest swift convert button and set App target build setting-> Swift language version: swift 4.0,
Hope this will help.
This Solution works when nothing else works:
I spent more than a week to convert the whole project and came to a solution below:
First, de-integrate the cocopods dependency from the project and then start converting the project to the latest swift version.
Go to Project Directory in the Terminal and Type:
pod deintegrate
This will de-integrate cocopods from the project and No traces of CocoaPods will be left in the project. But at the same time, it won't delete the xcworkspace and podfiles. It's ok if they are present.
Now you have to open xcodeproj(not xcworkspace) and you will get lots of errors because you have called cocoapods dependency methods in your main projects.
So to remove those errors you have two options:
Comment down all the code you have used from cocoapods library.
Create a wrapper class which has dummy methods similar to cocopods library, and then call it.
Once all the errors get removed you can convert the code to the latest swift version.
Sometimes if you are getting weird errors then try cleaning derived data and try again.
maybe you need to download toolchain.
This error occurs when you don't have right version of swift compiler.
In my case, all warn disappeared after I directly changed swift version from 2.x to 4.0 in build settings except two warn.
These warning related to myprojectnameTests and myprojectnameUITests folder. I didn't notice and I thought its relate to direct immigration from Xcode 7 to Xcode 9 and I thought I couldn't solve this problem and I should install missed Xcode 8 version.
In my case, I deleted these folders and all warns disappeared, but you can recreate this folder and contains using this:
file > new > target > (uitest or unittest extensions)
and use this article for create test cases:
https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/testing_with_xcode/chapters/04-writing_tests.html

Use Legacy Swift Language Version - Xcode 8.2

After updating to Xcode 8.2 the compiler throws one error for my App target:
“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.
But have it set to No in all targets I have. Tried to remove Derived Data, clean project dir, restart Xcode. Nothing helps. Anyone figure it out?
// Edited
Just to be sure: I have set to ALL my targets Use Legacy Swift Language Version to No and the project worked alright when compiled in Xcode 8.1. It doesn't work after updating to Xcode 8.2.
// Edit 21.12.
The issue has been fixed in Xcode 8.2.1
Found work around. I went through each target (and project settings, so both in the project and target) in my project, toggled the "Use Legacy Swift Language Version" from "No" to "Yes" and back to "No" for each. The project then built again.
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.
Follow these 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.)
Hope this work for you.
Fixed in Xcode 8.2.1.
Here is a copy of the integrality of the changelog of Xcode 8.2.1:
Swift
Resolved Issues
Fixed an issue that could cause building a project to fail with the error message “"Use Legacy Swift Language Version" (SWIFT_VERSION) is required to be configured correctly for targets which use Swift” when using a supported version of Swift. (29667880)
Xcode no longer warns about using deprecated Swift 2.3 code when the active scheme does not reference targets using Swift 2.3 code. (29671741)
Close Xcode and open the corresponding project.pbxproj in a text editor of your choice.
Replace SWIFT_VERSION = 3.0.1; with SWIFT_VERSION = 3.0; for all targets.
Reopen Xcode.
This is the only thing that worked for me...
For errors with pods. Basically we need to enable “Legacy Swift Language”. Select your pod framework (by clicking on it in the error navigator) and under Build Settings find “Use Legacy Swift Language Version”
Set it to “Yes”. Then “Build & Run” again to test it.
Check out this post: http://rebeloper.com/downgrade-swift-3-swift-2-3-xcode-8/
Well I've finally figure it out. I've removed the project and clone it again, restarted Xcode, run pod repo update and pod install and it worked. I've no idea why.
This did not work for us :( reverting back to Xcode 8.1 is best for now until Apple QA's their stuff before they release.
If its any consolation here are things we tried and got us very close. We got stuck at the Clean Failed:
rm -rf ~/Library/Developer/Xcode/DerivedData/ModuleCache
rm -rf ~/Library/Preferences/com.apple.Xcode.plist
restart Xcode and do a deep clean holding the option key
That got rid of the Clean Failed.
Adding this to your pod script
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
That is the way to have all pods conform to 3.0 and we actually got it to build, but at the end of compiling we got this 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.
How do we change the workspace so that all projects conform to swift 3.0? Where is that setting?
It turns out that Apple decided to reference a version of the swift language that doesn't exist yet within the pbxprojec file. They hard coded 3.0.1, and by manually editing the sudo XML in the pbx file back to 3.0 everything worked again. Apple apparently overlooked some simple QA work before they released 8.2
This could also explain why toggling between legacy in the build settings worked for some people.
I got the same error when converting parts of my app (both Obj C and Swift) to a framework, but in my case it was that the "Swift Language Version" under Build Settings wasn't set. I set it to Swift 3 (the only option), and the error went away.

Unable to use Charts framework in Xcode

I installed Charts via cocoapods to an Xcode project but I get the following errors on building it: 'No such module Charts' and 'ChartPlatform.swift : Method does not override any method from its superclass'.
I made sure to uncomment 'use_frameworks', in the podfile and open the project using the xcworkspace file. Not sure where I went wrong. I've always installed pods the same way and haven't had problems till today.
How can I fix this?
I ran into the same problem because I was using an older version of Xcode. The Charts framework only works with Xcode 8 and swift versions 2.3 or 3.0. Try updating and see if that fixes the issue.
In my case I just removed Charts.framework from Embedded Binaries and then added again rebuild the project (Cmd+B) the error has gone.

Alamofire and update for Swift 3

I just updated to Xcode 8 and to Alamofire 4.0, and I got some odd errors. The first one is a bunch of errors looking like this:
... warning: Missing file: ... is missing from working copy
This goes on for Download.swift, Manager.swift, Stream.swift, Upload.swift and Error.swift. How to solve that one?
Furthermore I got this one, only for alamofire, not for any other of my libraries:
“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.
And when I try to convert it, I get
Could not find test host for FieldSenseAppTests: TEST_HOST evaluates to ..."
I am able to fix it by setting Use Legacy Swift Language Version to "No" under Build Setting section.
There's no need to convert anything. Revert the changes you've made (reinstall Alamofire) and do the following:
Select your project (Pods I assume), select Alamofire as a target and go to build settings.
Wnder "Swift Compiler" you can find "Use Legacy Swift Language Version", which you need to set to "No".
Close Xcode.
Edit your podfile, comment out the line for alamofire.
Save and run 'pod install'. This will remove alamofire.
Edit your podfile, uncomment the line for alamofire. Make sure your alamofire version is 4.0
Save and run 'pod install' to install alamofire.
Open your Xcode workspace
Run migrator, select alamofire target. UNCHECK the suggested changes for alamofire and save.
Try to build.
I had the same exact problem and here is how I fixed it:
Copy your Xcode project folder and paste it into another directory.
Open and build the copied project to see if the missing file warnings went away.
If they did, replace your original project with the copied one.
As far as your 'Legacy Swift' issue, see this post.

Xcode 8 beta 4: Build fails with "The following binaries use incompatible versions of Swift:" error

With new Xcode 8 beta 4 we started experiencing the following error during CopySwiftLibs build phase:
Effective srcDirs: {(
<DVTFilePath:0x7f865961e970:'/Volumes/Data/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator'>,
<DVTFilePath:0x7f8657d02b20:'/Volumes/Data/Xcode-beta.app/Contents/Developer/Toolchains/Swift_2.3.xctoolchain/usr/lib/swift/iphonesimulator'>
)}
error: The following binaries use incompatible versions of Swift:
/Users/user/Projects/git/iphone-swift-1/DerivedData/myApp/Build/Products/Debug-iphonesimulator/myApp.app/myApp
/Users/user/Projects/git/iphone-swift-1/myApp/myAppApi.framework/myAppApi
myAppApi is a subproject in the workspace that contains some shared code (it uses Alamofire).
One thing to note: originally we converted project from Swift 2.2 to Swift 2.3, and then manually upgraded to 3.0.
Does anyone have any idea what might be causing this error?
Thanks!
I had the same problem, but managed to fix it by:
Clean the project.
Close project and quit Xcode.
Clean derived data.
Open the project again and it's there, all nice and working.
I did this on Xcode 8 using Swift 3.
You can also get this problem, if you have the scenario of your container app's code is Swift 2.3 and you're creating a new extension in Xcode 8.
To solve the above scenario...
Note: All code has to be in the same swift (compatible) version to compile without failure.
That being said, one way you could solve this problem is by sticking to Swift 2.3 and then setting your Extension Target's Use Legacy Swift Language Version to "Yes".
You can find that option while Xcode 8 is open as follows:
Select your app project root in the Project Navigator (on the left-hand side)
On the right-hand side, select your extension under the TARGETS
section
Once the extension is selected, click on the Build Settings tab
Scroll down and find Use Legacy Swift Language Version and set it
to Yes from its drop-down menu.
You can now build the project
Note: You might need to fix the overridden code in the extension templates since they were originally in Swift 3.
Before doing anything...
(If you can use Xcode 8.0-compatible with your project)
By default your project is set to Xcode 3.2-compatible
Select your app project in the Navigator (on the left-hand side)
Select Project Document in the Utilities Panel (on the
right-hand side)
Change Project Format to Xcode 8.0-compatible
Try to build your project.
If it doesn't work, try the other solutions proposed.
Note:You can even switch back to Xcode 3.2-compatible after fixing the error and it should work, but you "might" have other build problems later.
Recommendation:
Before debugging an existing project. Close your project and zip a copy of your project file if you did not create a Git repository when you created your project.
I just had the same problem after updating Xcode to 9.3. I fixed the problem simply by just cleaning the build folder. You can do this with Command-Option-Shift-K or in the option menu "Product" -> "Clean" (see screenshot)
I fixed this by deleting the embedded binaries in the project. To do this:
Open your workspace/ project in Xcode.
Navigate to the actual project file (with the General, Capabilities, etc. ribbon).
Go to General > Embedded Binaries, remove by selecting on the ones you don't want and then clicking the minus sign.
Note 1: You shouldn't have to delete them from the "Linked Frameworks and Libraries" section (they should automatically be removed when you remove them from the "Embedded Binaries").
Note 2: I have a lot of dependencies and am using CocoaPods. I have nothing in the "Embedded Binaries" and only the "Pods_[YourApplicationName].framework" in the "Linked Frameworks and Libraries" section.
I had various libraries integrated via carthage. However during the process I switched some of them to cocoapods and forgot to remove the old .frameworks file from the project target.
Removing them solved the build error.
I had the same problem.
My solution was to rename the 'myApp'-directory to 'myAppmyApp' and then I ran the app again. A new 'myApp'-directory was made a the app did run very well again on my iPhone.
A difference with your situation might be this: the name of my app, let's say 'myApp' in the directory 'DerivedData' was myApp concatenated with: '-'
Maybe this will help you.
You need to switch all the dependencies to swift 3.
In your case, Alamofire need to be switched to Swift 3 branch
I had the same error message after adding a Swift 3 version of a framework.
My target framework search path was still configured to find both swift 2 and swift 3 version of the same framework, so my project got stuck on swift 2.3 version.
For me, the solution has been to remove the old framework from my project directory and delete its folder reference from the framework search path.
So I just post the solution I found so far after an hour debugging.
Since Xcode 9, this can be tracked by the compiler log.
If you scroll down to the bottom of the compiler log, you will find this issue is caused by type checking crash.
Just had this pop up after upgrading to Xcode 10.2 ... one of my pods uses Swift.
Fix was to:
pod repo update
rm -rf Pods
pod install

Resources