Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code migration from Swift 2.x to Swift 4

We have big enough project which is built up with Swift 2.x and now Apple has just released Swift 4 so to move forward for latest version of Swift which path we can choose...

Do we need to migrate our code to Swift 3 first? Or we can directly migrate our code to Swift 4 using Xcode 9?

like image 786
RayofHope Avatar asked Jun 07 '17 07:06

RayofHope


People also ask

How do I transfer my swift 3 code to Swift 4?

Go to project navigator> Build Settings. search for swift Compiler - Language and change this to desired version.

How do I migrate to swift 5?

You will need to manually select the new scheme, then run Edit -> Convert -> To Current Swift Syntax to migrate the remaining schemes. Or you can create a scheme that includes all the targets from your project, and have it selected before running the migration assistant.

How do I update my swift code?

To convert just your project to the newer Swift version go to Edit -> Convert -> Convert to current swift syntax A popup will appear with a list of targets, including the pods. Deselect everything except your project target, the unit and UI tests and press convert.

How do I update my swift 3 to swift 5?

You need to redownload Xcode 10.1 from this page, convert your code to Swift 4, then redownload Xcode 10.2 and convert to Swift 5. The only other option I can think of is changing your Swift Version in your apps bundle and then seeing if it lets you convert but I don't think it will. Show activity on this post.


3 Answers

Yes, you must migrate your code in Swift 3 compatible version. Xcode 9 allows conversion/migration from swift 3.0 only.

enter image description here


Swift 3.2 is supported by Xcode 9 & Xcode 8 both.

enter image description here



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 covert into latest version of swift supported by your Xcode Tool)

(Xcode) Menus: Edit ► Covert ► To Current Swift Syntax

enter image description here

like image 138
Krunal Avatar answered Nov 07 '22 05:11

Krunal


Yes, you first need to migrate your code from Swift 2 to Swift 3, using Xcode 8.

Xcode 8 is the last version to support Swift 2.

Starting with Xcode 9, the supported Swift versions are 3.2 and 4

enter image description here

like image 22
Eric Aya Avatar answered Nov 07 '22 06:11

Eric Aya


Yes, you need old versions of Xcode . Old version are available here https://developer.apple.com/download/more/

like image 24
Laky Avatar answered Nov 07 '22 07:11

Laky