
Apple’s use of Swift in iOS 12 - glhaynes
https://blog.timac.org/2018/0924-state-of-swift-ios12/
======
ppeetteerr
I have been writing code for over 10 years and I can comfortably say that
Swift is one of the best languages today than many other languages at a much
later stage in their life (hey there Java!). I'm not talking about the
standard lib, I'm talking primarily about the language and how well one can
express their ideas with it without shooting oneself in the foot.

The only reason I suspect that Apple is not all over Swift is that many of
their programmers are the type of coders who like falling back to C when they
feel they need a performance boost. Perhaps they like the message-like nature
of ObjC. Dunno. I can say that I've been able to get apps to 0 fixable crashes
with Swift (some crashes are system level), not something I've ever done with
ObjC, let alone Java for Android.

~~~
dieterrams
It was a couple years ago, but I spoke with one of their engineering managers
about Swift adoption within the company. His response was that it was being
used for new apps/projects, but not so much for existing codebases.

Having worked on a large Obj-C codebase that began adopting Swift, there are
definitely some headaches involved in Obj-C/Swift interop, and you often
aren't getting many benefits of Swift unless your new code has few to no
dependencies on / is not depended on by Obj-C code, unless you can refactor it
into Swift.

Given how quickly it seems they've been forced to ship, I can understand not
wanting to deal with these issues, or not having the time to address them.

~~~
ppeetteerr
There are three advantages that I saw immediately upon switching to Swift:

\- It was easier to hire developers

\- Code was less prone to null pointer exceptions

\- There were fewer assumptions when deserializing JSON into a struct/object

~~~
mgoblu3
We moved a very large iOS app over to Swift, and the first two benefits are
really huge. I know people have opinions on these things, and both sides are
right, but the really strong typing and enforced nullability have been hugely
important to getting junior engineers contributing to the codebase.

Not saying that it's an unsolvable problem elsewhere, it's just an anecdotal
benefit we got

------
bunnycorn
A perfectly good rooster, considering that Swift only became usable at v3.0,
two years ago.

I've developed since for version 1, small utilities, and even for those
projects, it was not enough.

Version 4 and it's my favorite language to develop for.

~~~
Aaargh20318
I can't wait for Swift 5 when we finally get ABI stability, that's the last
major issue that's holding Swift back.

~~~
ken
That'll definitely be nice, for people already using the language, but I don't
know of anyone actually held back by that. I'm more concerned by issues like
lack of a good concurrency story, and lack of a good cross-platform story
(differing behavior on Darwin/Linux, no Windows support).

------
mamcx
For me, to make swift a total contender it need good support for non-apple
platforms:

[https://www.reddit.com/r/swift/comments/8zb9y1/state_of_swif...](https://www.reddit.com/r/swift/comments/8zb9y1/state_of_swift_for_androidlinuxwindows_on_2018/)

For that, I'm exploring with rust now, but certainly is far harder than use
swift.

I also look at nim, yet I think is too inmature for use in ios/android?

~~~
dom96
I don't think it's too immature. People have successfully targeted iOS/Android
with games in Nim.

~~~
mamcx
I judge from what little I can find. Exist a good reference in how do it?

Even if a keep rust I think nim cover a nice spot to add to the toolbet.

------
dep_b
Given the maturity of iOS it's not unexpected to see the uptake of Swift so
slow. Though it's lacking a "total binaries" number.

Swift is a great language to work in.

~~~
sgt
I have to comment on this. Swift is one of those languages that make me look
forward to opening up Xcode in order to start writing code. It's just such a
fantastic language, and it's hard to explain why until you've actually started
writing code in it.

~~~
kapuru
Honestly curious: What makes it such a fantastic language?

~~~
sgt
I think optionals are my favorite feature. That may be due to me coming from a
Java background (which also has optionals since 8, but I feel it's rather
clumsy compared to Swift and other modern native languages).

By doing optional chaining you can do something like: if let name =
result.person?.firstName { ... } which only evaluates firstName if person is
not nil, and then stores the result in name which is immutable.

It's easier to avoid mutable code in Swift than in many other languages. For
this reason I would love to start working with Swift on the backend at some
point in the future.

I like extensions, being able to extend any class I want by just typing it
into any file I want. This helps with iterative development and trying
something out.

Speaking of iteratively, if I want to try something quick, I can also drop
down to a shell and start the Swift REPL to experiment.

I like how built-in functions like zip and mapValues are available, so it in
some ways has a Pythonic feel. I like the syntax of building strings by just
taking a variable name and going let s = "Hi there \\(name)!".

There are lots of other things I enjoy, such as subscripts (see why here:
[https://docs.swift.org/swift-
book/LanguageGuide/Subscripts.h...](https://docs.swift.org/swift-
book/LanguageGuide/Subscripts.html)) and

Some things I would like to see improved is Xcode itself and also Swift's
capabilities in the backend.

~~~
kapuru
Thanks for the answer!

I've been waiting impatiently for a better Swift backend ecosystem, because
I'd love to use it for web development as well.

~~~
Eric_WVGG
I’m having a great time in Vapor 3.

~~~
briandear
Vapor is pretty amazing. Super fast and pretty fun to work with; also a very
friendly community. Ray Wenderlich’s team as well as Paul Hudson also have
some great books on server-side Swift for those looking to learn this stuff.

------
amirmasoudabdol
I assume we'll see it being more used by Apple at the system level a year or
two after they got the ABI stable. Somewhere around iOS 14 or 15 maybe.

------
whitten
While I think dyld is probably short for "dynamic load", I initially read it
as 'Dylan Language Deamon" when I read the phrase 'shared dyld cache'.

I know Apple was heavily involved in the Dylan language several years ago.
Does anyone know if Swift was influenced by Dylan ?

~~~
dwaite
dynamic libraries on macOS are dylibs. There is a debate whether 'ld' is short
for load/loader, or link editor. So you can either read it as the dynamic
library load tool or the dynamic link editor.

A shared dyld cache would be a cache of metadata used for linking, but not
sure if that is for link-time or runtime.

------
catoc
66 binaries out of how many in total?

------
flashgordon
Has there been widespread adoption (or migration to Swift) in "large"
companies for their flagship products outside apple?

------
pier25
What about macOS?

------
elcritch
I wonder if there is a way to correlate the number of bug / issues related to
binaries with Swift. It’d be interesting to see if Swift correlates positively
with bugs/crashes.

~~~
LeoNatan25
If anything, since a lot of stuff is being rewritten from scratch, a lot of
new bugs appear that were not there. At least that's my experience on the Mac
with software that has been rewritten in Swift.

Obviously, it's not Swift's fault for that, but even if people at Apple make
rookie mistakes such as using force unwrap operator, it tells something about
the language.

~~~
dep_b
> Obviously, it's not Swift's fault for that, but even if people at Apple make
> rookie mistakes such as using force unwrap operator, it tells something
> about the language.

It's still often suggested by Xcode if you use an optional which has not been
unwrapped in any way. "Click here to make error go away" adds an !.

~~~
wool_gather
Good point. Fortunately this fixit was improved over the summer:
[https://forums.swift.org/t/resolved-insert-is-a-bad-
fixit/10...](https://forums.swift.org/t/resolved-insert-is-a-bad-
fixit/10764/102) I believe it made its way into Swift 4.2/Xcode 10.

~~~
dep_b
Good stuff. Now to fix my only other pet peeve which is declaring IBOutlets
with a ! by default. In the ideal world IBOutlets would be checked compile
time unless they're declared with a ?

~~~
wool_gather
Well, they have to be Optionals one way or another, because they can't get
hooked up until after init[0], and Swift won't allow that. But yeah, I imagine
this is on someone's todo list somewhere. IB already knows whether things are
connected properly, and actually so does the source editor, since it shows the
little circles in the gutter.

\--

[0] Unless you could invert the order of the unarchiving...not sure what
difficulties that would cause.

------
raverbashing
Glad to see Apple moving away from ObjC (when it makes sense to).

This seems to contrast MS when they released .NET but shied from using it in
their own systems (though I might be wrong)

~~~
pjmlp
SQL Server Management console, Visual Studio, Windows Phone 7, Silverlight.

Then there was Longhorn, which failed more due to internal politics than due
to technical issues, as Midori later has proven just to be killed by
management, as decribed by Joe Duffy postmortem reports.

WinRT/UAP/UWP are built on top of improved COM, and .NET has a native
personality for them, using AOT compiler for WinRT/UAP (MDIL) and UWP (.NET
Native).

Most of the new UWP stuff is written in .NET Native, with C++ taking care of
the UWP runtime infrastructure, and the DirectX composition engine (Visual
Layer).

The majority of Windows UI team UWP and FluentUI demos are usually done in
.NET Native.

~~~
raverbashing
Thanks for these examples. Do you know since when was SQL Server Management
Console done in .NET? (to be fair the last one I used was around 2008)

Silverlight was more of a platform than an "internal product" and it was based
on .NET so it was only natural (it doesn't seem to have taken off though)

And yes .NET makes COM usable (well it is usable using MS libraries in C/C++,
otherwise, forget about it :) )

~~~
maxxxxx
Actually Visual Basic made COM usable :)

~~~
pjmlp
I would say Delphi did it better, until VB 6.0 that is, but then again I am
biased. :)

------
flocial
Would be nice to know what share of total binaries that represents.

On a side note, iOS 12 was great but seems riddled with memory leaks that
eventually require a reboot every few days.

~~~
alphabettsy
I’ve been running iOS 12 since the early betas and only rebooted for OS
updates. Sure it’s not an app or something?

~~~
flocial
There's one particular mobile game that is suspicious... However, this issue
was nonexistent with iOS 11. The memory diagnostic app shows the "Other"
section constantly growing and not being released.

~~~
saagarjha
> The memory diagnostic app shows the "Other" section constantly growing and
> not being released.

Are you sure you're not talking about storage space? I don't know what memory
diagnostic app you're talking about.

------
nsmith14
What's the solitary binary that used Swift in iOS 9?

~~~
masklinn
Calculator:
[https://twitter.com/jckarter/status/650142048444526593](https://twitter.com/jckarter/status/650142048444526593)

------
thelastidiot
A bit useless. Are they using it in the top ten (mail, web, cal, clock, etc.)?
How much of Swift compared to ObjC code? Those are the real answers I would
expect to read in your article.

~~~
coldtea
And all those answers are IN the article.

> _Are they using it in the top ten (mail, web, cal, clock, etc.)?_

No.

> _How much of Swift compared to ObjC code?_

Much less.

It makes sense too. You don't rewrite perfectly good programs in a new
language just for the fun of it.

~~~
tormeh
>perfectly good programs

The Holy Grail of software engineering

