Convert from Swift 3.0 to Swift 2.3 - ios

I have a static library that I converter from old Swift to Swift 2.3 and later to Swift 3.0.
Now I need both version (2.3 and 3.0) of the library, but I forgot to take a backup of version 2.3. And I only have 3.0.
Is there a simple way to convert back from Swift 3.0 to Swift 2.3?

Simple, not really, but this will work.
If you don't have it, download XCode 7.3.1 from Apple
Open your library in the 7.3.1 version and correct whatever errors appear
Migrate the corrected code from step 2 into XCode 8.2 or lower (8.3 will not support Swift 2.3)
As mentioned in the comments, maintaining your code in a version control system will spare you problems like this in the future, and is generally just a good idea.
You don't even need to set up your own system, since git is part of MacOS, and XCode can handle simple git features for you.

Related

Swift framework for all Xcode versions

I provide a Swift framework for my customers.
It would only work in Xcode 10.3 (Or am I doing anything wrong?)
For other Xcode, it does have Swift compatibility issues.
So I am planning to release a series of versions of my framework so that a customer with a particular Xcode version can have the respective framework version of mine.
And it is pretty complex. Because for every release or bug fix I need to generate a bunch of versions.
I just want validation if this is the right approach.
How do I simplify this?
The compatibility issue you have is not from the version of the Xcode, is from the Swift version of the Framework. There is a difference.
In every project you can set the Swift version, but unfortunately you can't have more than one swift version per project. The current accepted ones are Swift 4, Swift 4.2 or Swift 5, as you can see in Xcode > Target > Build Settings:
Xcode 10.0 was the last version to support Swift 3 and is currently obsolete. I wouldn't create a framework version for it.
So, I would recommend you to either focus only on the latest Swift version and create a new Framework version every time a new Swift version appears (the most common approach), or start with the current three Swift versions and give them maintenance until the Swift version is deprecated.

Unsupported Swift Version 3.x in Xcode 10.3

I keep downloading sample codes and many times it says "Unsupported Swift Version 3.x...Use Xcode 10.1 to migrate the code to Swift 4".
Why is it not possible to migrate to Swift 4 using Xcode 10.3 or Xcode 11 beta?
More importantly, I am using Swift 4.2 in my own Project that has several dependancies as well through Pods. If I don't upgrade to Swift 5.1 or later, it seems my own project would start getting such errors in Xcode 12 or so, correct? While I can convert my own code to Swift 5.1, I have no idea if dependencies such as SwiftyDropbox would migrate to Swift 5.1 so easily. What implications it would have for my project in future and what could I do to future proof my project in that case?
Ask Apple. The company has decided – certainly for good reasons – to migrate files only to the Current Swift Syntax. Feel free to create legacy system partitions with older versions of Xcode to migrate code step by step.
The grace period to update the Swift version is long enough to ensure a smooth transition. At least Xcode allows to use the 3 most recent Swift versions in the same project. However you are responsible to maintain the version control. Check the dependencies periodically for updates. If a dependency is not able to release an update within the grace period it's not much good.

Using Swift 3 in Xcode 10.2 - Command /Library/Developer/Toolchains/swift-3.0-RELEASE.xctoolchain/usr/bin/swiftc failed with exit code 1

My goal is to get the new Xcode 10.2 compile and run our projects that are build using Swift 3 and 4.2 (some cocoapods too) and since Xcode 10.2 comes with Swift 5, an unsupported swift error came up when trying to run the projects out of the box (this is expected):
The solution here is to use an older toolchain as stated on blogs like this, which i did.
All good so far. However, after installing the Swift 3 toolchain from Swift.org, compiling the project will bring the following error:
Command
/Library/Developer/Toolchains/swift-3.0-RELEASE.xctoolchain/usr/bin/swiftc
failed with exit code 1
I already deleted Derived Data folder, cleanup pods (my podfile) and reinstalled them, restarted Xcode and Mac multiple times.
Running xcrun -f swift and swift --version will indeed print the correct swift 3.0 toolchain
Yes, I know I could just stay with Xcode 10.1 and don't have these issues. Code migration to Swift 4 is also an option but we don't have the time at hand for now so I'm trying to workout this walkaround.
Please help me to resolve this issue, I'm completely stuck. Thanks in advance.
Xcode10.2 Release Notes
Swift 5 no longer supports the Swift 3 Package.swift tools-version.
Packages still on the Swift 3 Package.swift tools-version should
update to a newer tools-version. (41974124)
Swift 5.0
Source Compatibility As with Swift 4.2, the vast majority of sources
that built with the Swift 4.2 compiler should compile with the Swift
5.0 compiler.
However, the Swift 3 compatibility mode will not be supported in the
Swift 5 compiler. Swift 4.2 is the last release of Swift to support
Swift 3 mode. There are important changes to both the surface of the
language and the interior of its implementation in the releases
following Swift 3 that will be the basis of future (and lasting)
source and binary stability.
Using Swift 4.2.1 toolchain work for me.
But https://swift.org/download/#using-downloads tips:
To submit to the App Store you must build your app using the version of Swift that comes included within Xcode.
Upload to apple connect probably reject by apple.

Migrating a module written in Swift 3.0 to Swift 2.3?

The company I currently work for supports legacy products written in Swift 2.3 (I don't agree with it). At the moment they currently want to continue rolling out features supporting the legacy version and thus, I'm currently in a bind concerning a pod written in Swift 3.0.
I attempted to convert the syntax back to Swift 2.3 by installing Xcode 7.3.1 with the intention of hopefully migrating that code. Unfortunately, since it's a module written in Swift 3.0 my efforts were futile.
I'm out of suggestions though I'm not opposed to writing the code in the module in Swift 2.3 however I know I'll be looking at a tedious process for the long run. What steps should I take to migrate a module written in the most updated version of Swift back to version 2.3?
Firstly, you can use Xcode 8 to do this. Select each of your schemes and then set 'use legacy swift version' in build settings to yes. Compile and then run. Swift will start presenting lots of errors. For example, this code (in swift 3):
SKAction.rotate(byAngle: CGFloat(M_PI_2), duration: 10)
is
SKAction.rotateByAngle: CGFloat(M_PI_2), duration: 10)
in swift 2. You have to manually fix all the errors that swift says, so you need a clear understanding of the old swift syntax.

How to change the new version RAC(ReactiveCocoa) in a project?

When I open my iOS project built before the iOS 10 was released, I find it has an error about the ReactiveCocoa because of the version of swift. I try to use the method provided by Github, but it seems I failed. There are at least 18 errors when I try to convert to current swift.
There's RAC Releases for each Swift version, so if you're updating an old(er) codebase to a new version of swift, you will need to update RAC to the appropriate version.
RAC 4.x is for Xcode 7.3.x/Swift 2.2.x or Xcode 8.0.x/Swift 2.3.x
RAC 5.x is compatible with Swift 3.0 and 3.1.
RAC 6.x (not yet released) will be for Swift 3.1 with preliminary support of Swift 3.2 and Swift 4.0.

Resources