Swift 3 Upgrade Issues Conversion - ios

When I try to compile the repo https://github.com/Bernie-2016/fieldthebern-ios I run into a swift conversion issue. "This workspace has projects that contain source code with an earlier version of swift."
"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."
When I try "edit -> convert -> To current swift syntax" Opens up selecting targets to convert, many of which are frameworks. Proceeding with the conversion yields >3,000 errors in the console.
I think the solution is to grab the latest libraries via cocoapods and then complete the conversion with the main project code but am not getting any luck.

Make sure that your podfile references a Swift 3 branch for every Framework.
Then you need to cd into your project folder using Terminal
Run: pod update
once done, open your project in Xcode and you should be prompted to convert into the latest Swift Syntax automatically, if you weren't you have to do it manually in
Edit > Convert > To Current Swift Syntax…
when all changes are prompted, click update
this will again display 999+ errors but no worries.
run the clean command Cmd + Shift + K and then build Cmd + B
you should have no more errors and if you do have errors, they shouldn't be a lot and you would have to go through the errors manually to fix them
its completely normal, it became a routine thing for me when using CocoaPods

Related

Xcode 10 convert to Swift 4.2 fails

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.

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

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.

Converting to Swift 3 error: "Convert to Current Swift Syntax Failed Could not find test host for..."

When I try to run my project that ran perfectly before upgrading to Xcode 8 I keep getting the 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.
After trying to convert to swift 3.0 i continually get the error:
Convert to Current Swift Syntax Failed Could not find test host for
CastleTests: TEST_HOST evaluates to: (location of my file for my project and test folders)
I've tried converting another project to swift 3 and it worked perfectly fine, but this one will not work. All of the locations of the products are set up the same as how the ones in the working project are I'm confused to why i keep getting this error
i)Select every target of Test in Project. ii)Navigate to General tab.
iii)Host application name is empty ,so Update with appropriate host name .
Build again and it will work fine .
So if you select your test target under the general tab, you should see a testing section and a "Host Application" prompt with it. If you select the field to the right, you should be able to select your host application from none to your host.

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