From Swift2 to Swift 3
By glazou on Monday 27 February 2017, 15:45 - Mac - Permalink
I am migrating a rough ~9000 lines of Swift 2 code to Swift 3. So really a small thing. And this is a mess of epic magnitude; the time needed to do that is not counted in hours but in days. Even if Swift is beyond 1.0, nothing seems stabilized. Some naming choices are totally ridiculous, unintuitive, painful to remember. Worse, they sometimes drastically change between two versions of Swift.
The whole naming thing of parameters is totally crazy. Let's take the example of some
removeAtIndex()
in Obj-C. The prototype for that in Swift 3 would be
remove(at: index)
. That's über-cool when you read the prototype. But in
your code, you have very little chance to have your parameter named
'index'. For instance remove(at: currentEntryRef)
. And bam, you've lost
the connection to the Obj-C function. Most of my own functions end up with a leading underscore in front of each parameter...
Suppose you have 65 and you want "A". You need to convert
your 65 into a UnicodeScalar. Until then, acceptable. Then from your
UnicodeScalar to a String. But String(UnicodeScalar(65))
won't work, you
need String(describing: UnicodeScalar(65))
but hey, that's an
Optional("A")
so you really need String(describing:
UnicodeScalar(65)!)
... Urgh. Oh and in Swift 2, it was String(UnicodeScalar(65))
and that's all. I miss JS's String.fromCharCode()
so much. I
miss JS so much.
Interestingly, the mobile team of Mozilla explained what it took to migrate Firefox for iOS from Swift2 to Swift 3. And we're now counting **in weeks**. This is clearly awful, Swift is not stable enough. While it should be very simple for a JS author to move from JS to Swift, it's not the case any more. It's also far too expensive to move from one version of Swift to the next one.
Instead of adding super-useful stuff like throwing computed properties (that are really, really useful to implement W3C DOM/CSS OM interfaces), Apple changed things that implied hours and hours of code tweaking just to build again even the first file of my repo in Swift3... Woooof.
I find this so depressing. Awful.