142 points · by gok · 7y ago · 67 comments
It's a really amazing system, but the sparseness of proper official documentation, Xcode bugs (like marking errors on a line far away from where the problem actually is) and the seemingly secret Swift magic that's used to implement some features, means everyone is stumbling blindly in a labyrinth, relying on each other's shouts to navigate.
Resources like this post and https://swiftui-lab.com and https://mecid.github.io are a godsend.
And of course you need to be on the bug riddled Catalina to get any real SwiftUI development done (live previews).
UI development in the Apple ecosystem has always been a bit rough, but I've never run into _this_ many problems in such a short amount of time, all while following their official tutorial.
Real shame too. I've talked about this with some of their tools team I went to school with. I don't know what's in the water in Cupertino but I don't think Apple devs are getting the same experience out of XCode as their actual users.
This was complex and somewhat tricky to get right, which is why sometimes you see errors that seemingly have nothing to do with the original problem. Closures and generics were especially problematic for the old design to deal with.
Since Swift 4.2 there has been an ongoing effort to rewrite diagnostics so that the solver keeps enough breadcrumbs from failed constraints to piece together an accurate error message. On the master branch the type checker’s test suite has lots of examples where diagnostics have improved significantly.
Rumors are this was pushed out this year in order to respond to Catalyst’s public unveiling. Word is there was a little internal politics over what is the “preferred” method for apps on the Mac.
At least, that’s what I have seen on Twitter. Personally, I think it was mainly about wanting to get the Swift features in place to support it and since Swift is largely evolved and developed in the public it needed to come sooner, rather than later.
Edits: typos
Many parts of the SwiftUI documentation are still marked [Beta] for all OSes. Or maybe it's just saying that the documentation is beta, though it's more like Alpha..
EDIT: Apparently it says Beta only in the offline docs on Xcode 11.1 (not sure about 11.2)
It is not, aside from a smattering of pages I am assuming that have not been updated: https://developer.apple.com/documentation/swiftui
We're starting on a major rewrite of the Redux core docs [1], and as part of that we'll be encouraging folks to use RSK as the default way to write Redux code.
(Note that we're also discussing possibly renaming RSK [2] to avoid confusion over the word "Starter" - a lot of folks are mistaking this to mean that it's only good for beginners or that it's some kind of project CLI tool.)
[0] https://redux-starter-kit.js.org
...and this thread where two interested parties discuss SwiftUI briefly:
https://twitter.com/raphlinus/status/1190025792534798338
...and also this blog post: https://raphlinus.github.io/rust/druid/2019/10/31/rust-2020....
There are lots of apps which are simply specialized CRUD apps. Personally, I love building them. The current state of SwiftUI is sufficiently developed for this kind of app.
Best of all I generally have to write most game UI views just once for iOS/macOS (because they won't use native widgets anyway) with a few #if differences.
- open source code - if something is not clear I can always CTRL + click a widget and see how it's implemented
- there is official formatter for Dart which formats widgets on save (IMO essential things for layout in code)
- documentation is good enough
- it works on any iOS version
- it works on two popular IDEs which support plugins
I had great hopes for flutter, but this kind of cooled me down instantly.
Regarding bugs you have mentioned... I've seen worse stuff, but that's how it is with new technologies.
I also filed a bug about tests in Dart not being able to be code folded properly in IDEA and it was fixed within about a month. The developers of that plugin really take it seriously. Totally awesome.
It's 'new' and it has 'Apple' behind it. I had to google to make sure I wasn't missing something. It's 'declarative', it has 'design tools' and it works on 'apple only platforms' [0]. Are those supposed to be killer features?
There was a twitter question that really made me think - it asked what framework, language or tool of today, would give a competitive advantage, if you had it 15 years ago [1]. I couldn't come up with a single thing, and that was a depressing realization.
Is SwiftUI that tool that will be looked back on in 15 years? Is Swift that language? For me, no. It's not even bloody cross platform...
[0] https://developer.apple.com/xcode/swiftui/ [1] https://twitter.com/tolmasky/status/1183146890293956609?s=20
Being able to target desktop, phone, tablet, and TV devices while reusing 80%-90%* of the same code for all of them, is cross-platform enough for me. :)
macOS, iOS, iPadOS, tvOS, and soon AROS if the rumors have weight, comprise over a billion users. And if you're someone who likes to tinker with the latest tech in your apps, Apple has the best ecosystem because most of their users quickly upgrade to the latest OS, compared to Android etc.
* Ass estimate
What magic are we talking about? I thought all the new stuff was RFC'd right after SwiftUI was announced.
So e.g. you can’t use `some`-typed variables or stored properties.
1. What the ... ?
2. That's really clever.
3. That's a really bad idea (see 2)You say "nil messaging", I say "pervasive optionals".
You say "autorelease pool", I say "deterministic delayed free".
You say "proxy objects", I say "first class variables".
And all of these aren't particularly clever in the sense of "so incredibly complicated that nobody can figure them out".
Maybe "hacky".
To give you an example: pull-to-refresh isn't there yet. You have to build it yourself. I looked for a searchbar and I built it myself as well.
However building the GUI itself is very fast, because it compiles and immediately previews your code. The preview can be changed with the mouse, which updates your code again. That aspect is very, very nice and made my client smile when we were adjusting some padding, font sizes, image sizes etc. on the fly.
(Also, i couldn’t get a list of all the types of views and their documentation anywhere in apple’s documentation).
Text("Hello,").italic() + Text("World!").fontWeight(.bold)
Works with multiple lines, multiple font sizes etc.Another undocumented gem that I discovered via the SwiftUI community. You should be able to build a constructor that reads a string with formatting codes like Markdown and spits multiple Text views.
let stack = VStack {
if myState {
Text("Hello")
} else {
Rectangle()
.fill(myState ? Color.red : Color.green)
.frame(width: 100, height: 100)
}
}
Type: VStack<
_ConditionalContent<
Text,
ModifiedContent<_ShapeView<Rectangle, Color>, _FrameLayout>>>
How does an `if` expression get inferred as a type `_ConditionalContent<...>`? Is there some magic support for SwiftUI in Swift? Does it desugar into something like: let stack = VStack {
ConditionalContent(myState,
Text("Hello"),
Rectangle()
.fill(myState ? Color.red : Color.green)
.frame(width: 100, height: 100))
}
?So the language feature isn't tied specifically to SwiftUI (though SwiftUI is the only supported client at this point), but it supports that general kind of transformation.
https://github.com/apple/swift-evolution/blob/9992cf3c11c2d5...
In other languages like rust and Haskell, the branches of if need to agree on their type so I found this a bit confusing.
Is there some kind of embedded DSL stuff going on here?
Exactly. It's a (at this point, unofficial) Swift feature called "function builders." The types end up being the same, because the conditionals are represented as wrapper types.
So
if count == 0 {
EmptyView()
} else {
Text("\(count)")
}
would result in a type something like `Conditional<EmptyView, Text>`.https://github.com/apple/swift-evolution/blob/9992cf3c11c2d5...