Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Convert my Swift Code back to 2.3

I downloaded the XCode Beta 8 and converted all of my swift code from Swift 2.3 to Swift 3. It has caused way too many problems for me and caused me to start a project I've been working on for around 4 month. How do I convert my code from Swift 3 back to Swift 2.3?

like image 291
Adrian Humphrey Avatar asked Oct 20 '25 11:10

Adrian Humphrey


2 Answers

On the build settings for the target switch "use legacy swift version" from no to yes.

enter image description here

That would switch the compiler back to the sane 2.x but won't change the code itself. The scope is limited to the new targets created for projects on older version of swift.

We have a potential issue though, with that what is a "legacy version" in the future version of Xcode might change.

like image 93
Anton Tropashko Avatar answered Oct 22 '25 03:10

Anton Tropashko


First of all save a backup of your current project. Now!

Next, you mean Swift 2.2 right?

If you don't have a backup and you're not using a version control system I believe the only way is opening your project with Xcode 7.3.1 and manually fixing the errors so to make the code compatible with Swift 2.2 again.

If you are lucky

Even if you think you are not using a version control there's a chance Xcode automatically created a local GIT repository for you. To check this open a source file of your project and then select View > Version Editor > Show Version Editor.

Now the main area is split in 2 columns. At the bottom of the central column that separates the 2 source codes there's a button having an icon similar to Time Machine). Press on it.

Now if below the right column you can select a different date then you are actually using GIT. Just pick a date previous to the conversion and repeat for every source file in your project.

like image 25
Luca Angeletti Avatar answered Oct 22 '25 04:10

Luca Angeletti