Xcode 10.2 is Out
Tuesday, March 26th, 2019This morning, after I updated to macOS 10.14.4, I noticed that Xcode 10.2 was out with Swift 5, and that has the new Strings, and the ABI compatibility, and a host of new things. So let's get that going, and see how it changes things. I really haven't read what is new in Swift 5 - other than the new Strings, so that will be something to read up on this morning.
What I've found in converting an ObjC project is that a few of the localizations needed to be cleaned up - Xcode did that just fine, and then it built and ran just fine. But for the Swift project, it complained about the use of index(of:) and suggested that it be changed to firstIndex(of:) - which is fine, but I don't know that anyone used to coding for very long makes that mistake - but OK... I get it.
The next one said that in this code:
ans.append(ascii[self.index(of: c)!.encodedOffset])
needed to be changed to:
ans.append(ascii[self.firstIndex(of: c)!.utf16Offset(in: self)])
and figuring that out took some time.
Specifically, they deprecated the encodedOffset - which they say was being misused. And then didn't really give me a replacement. I had to fiddle and search the docs for what to put in it's place. And given that this is coming off a call to self - how is it that utf16Offset() doesn't default to that?
In any case, I got that fixed, and then I refactored the code for pattern from:
let ascii: [Character] = ["a","b","c","d","e","f","g","h","i","j","k", "l","m","n","o","p","q","r","s","t","u","v", "w","x","y","z"] var ans = "" for c in self { ans.append(ascii[self.firstIndex(of: c)!.utf16Offset(in: self)]) } return ans
to:
let ascii: [Character] = ["a","b","c","d","e","f","g","h","i","j","k", "l","m","n","o","p","q","r","s","t","u","v", "w","x","y","z"] var ans = "" let src = Array(self.utf8) for c in src { ans.append(ascii[src.firstIndex(of: c)!]) } return ans
I just didn't like the way the encoding was being handled, and that got to be a real annoyance... so by just converting it to UTF8, and then using that array for indexing, I was able to do the same thing - and it looks a lot cleaner.
I'm less and less a fan of the speed with which they released Swift. I understand they needed to get it out in the wild, and they had to answer requests for features, but they added too many too quickly, and without the long-term consideration that they are usually known for. I mean look at ObjC... the classes changed a little, but the language was shipping product for 5 yrs, and Swift has been around for 5 yrs, and it's still not close to stable.
Part of it is also that they stuck with OOA&D, and that's got to be a killer.