Adrian Humphrey
Adrian Humphrey

Reputation: 450

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?

Upvotes: 4

Views: 9039

Answers (3)

Anton Tropashko
Anton Tropashko

Reputation: 5816

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.

Upvotes: 7

Jacobo Koenig
Jacobo Koenig

Reputation: 12534

I feel you. Also learned this lesson the hard way!!

What (kinda) worked for me was opening the project in XCode 7.3.1 which reduced the errors from 230+ to 60. I was able to revert to Swift 2.2 manually doing changes such as changing Data back to NSData. If you know what changes Swift 3 made (Google it) then you might be able to fix most of your project.

Good luck!

Upvotes: 1

Luca Angeletti
Luca Angeletti

Reputation: 59536

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.

Upvotes: 2

Related Questions