If you’re at WWDC stop by the labs and say hi!
It seemed crazy and old school to me to have the UI stuff that IB generates stored in XML - I definitely thought it should generate the same code that you would write to do it programmatically.
Also, the code for building UIs programmatically has been so unnecessarily complicated. Like building a collection view with all the functions needed and boilerplate code compared to the few lines we saw in the demo.
This seems so simple and declarative. It makes me feel a lot better about my future as an app developer. Thanks again!
Most good ideas are old school. Data is more powerful than code because it can be analyzed in more ways - for instance, you can extract all the UI and text from an app, localize and re-insert it, then verify the UI won't break, all without having to execute the app.
If it's all in code you may not be able to get to some of the views or even know it's there. This is called the rule of least power - an example of getting it wrong is C++ iostreams.
Of course I'm sure SwiftUI has solved this.
It's no surprise that XML seemed more attractive when your alternatives were Java or, even worse, Objective C. But really both options are absolutely terrible.
Thankfully we are very slowly making some steps forward again with Swift.
Honestly, if not for SwiftUI, I find developing interfaces in Android to be infintely faster than either fighting Apple's Interface Builder or building things by code in Swift.
Well you know, Cocoa and its predecessor OPENSTEP were built on the idea of using IB to compose interfaces out of actual objects that then got "freezed" into a file. So, no code at all, that was the idea.
Building views programmatically was the old school way even back then. ;)
What is so astonishing about SwiftUI is that it's simultaneously the most impressive looking visual GUI builder I've ever seen... and the most terse, diff-able syntax I've ever seen. I can't think of anything that has combined these two properties quite so successfully.
The idea behind Interface Builder is that it writes the class instances and their properties using NSCoding, and they're decoded at runtime and assigned to your IBOutlets just as if you had initialized them in code, set their properties, and assigned them to instance variables yourself. XIBs were introduced with OS X Leopard as a text-based way to store the files in source control, but they're still compiled into binary NIBs when the project is built. You're not supposed to hand-edit the XML.
It must be so much fun to work on a project that impacts so many developers. Thanks again!
FTD's syntax isn't nearly as nice as SwiftUI, but there's many similarities.
https://github.com/Shopify/FunctionalTableData
Purely for our own vanity - did Apple engineers take any inspiration from FTD? Or just independently set out to solve the same problems we had?
Apple is famous for making great on-stage demos that collapse once they're faced with the real-world (eg: basically anything related to having a great xcode experience)
Edit: Also, thank you!
I thought they were crazy strict and would, like, fire people for posting on forums or Twitter
@State var model = Themes.listModel
I haven't tried it out, but the above looks more like MobX: @observable model = new MyListModel();This is the sort of thing that will become clearer as real developers start using it. And I'm sure Apple will learn a lot as people start building bigger apps with it.
Almost no large scale app uses storyboards for most of their ui....
So I end up doing both. The problem (and I've seen this for many years with other similar systems), is that you have to become relatively comfortable with both approaches, so you can make informed decisions about when to flip back and forth. When can I do this with IB even though it's a teensy hacky vs when should I just subclass UIView and take over layoutSubviews and friends?
That's been my experience at least. YMMV.
In the keynote it was mentioned that SwiftUI would work across all Apple products.
Will it work on previous versions or only the latest iOS/macOS/etc?
However: I've never used React or any of its derivatives, so this is mostly inference. Is this take accurate or not? In theory, could you scale SwiftUI to build something like Logic, Blender, or Photoshop (for example)?
Also, have any declarative UI frameworks been released that feature a "platform" layer, where you get to define how your declarative code actually turns into UI, widgets, and behaviors? It seems that SwiftUI relies on (encoded) assumptions of what an ideal UIKit or AppKit app is supposed to look and feel like, and it would be really powerful if we could mess with this foundation or even swap it out entirely.
(It's very possible I'm mixing up reactive/declarative/reactive-UI concepts since I'm not too familiar with the territory.)
Honestly, this is something I've been struggling with coming to terms to for a while.
Really, what mobile app isn't just a CRUD thing? Literally every 3rd party app I can think of on my phone talks to some REST service in some way. Even the video games, photo editors, notes apps, etc. They all use the cloud where the cloud contains most of the business logic and the app is a thin visual client proxying the data.
You could argue that, for example, a first person shooter is not CRUD heavy. But after the match, when you're looking at leaderboards or sending friend requests or chatting with your friends in the lobby...guess where that UI is updating from?
Yep, another CRUD API. It's everywhere. I really want someone to prove me wrong because I want to expand my horizons - what the hell isn't a CRUD thing these days, other than completely offline apps?
We’re all just building CRUD apps."
> The combination of procedural and declarative program code has found success in, for example, GUI element layout. The most familiar example is perhaps HTML, CSS, and DOM combined with JavaScript. The QTk library [12] in Mozart/Oz, Glade [7],XUL [16], XAML [34], and XForms [5] serve as further examples. Some of these systems, along with rule-based systems such as Drools [27], Jess [11], and R++ [14], also support concisely specifying declarative rules for maintaining consistency across values in user interfaces. Property models are distinguished from these systems by not only providing the ability to create rules that assist introducing a valid result but also by providing an explicit model of the dependencies these rules create. Inspecting the state of the model enables generic algorithms (e.g., for widget enablement) for user interface.
There's nothing stopping you from writing imperative, side-effect heavy code. But it's something you deliberately opt into, usually on the edges of the program, rather than something you have to deal with by default. Absolutely nothing about React discourages this.
SwiftUI tries to do clever stuff under the hood to only update the portions of the view hierarchy affected by the state change for performance.
Haven’t had the chance to dig deeper, but the comparison between the UITableViewController and that snippet containing just declarative code looks absolutely promising.
The only downside is that we’ll have to wait one or two years before we can use it if older iOS versions still need to be supported. Let’s hope for extra quick adoption of iOS 13.
That really is a bummer, I have an iPhone 6 and it's still alive and kicking.
was rocking the 6
day after WWDC SwiftUI announcement: look ma, shiny new xr lolThe livestream hasn't been uploaded yet but I'm sure you could find it in one of the live blogs.
…have you taken a look at development for Apple’s platforms lately? Nobody has been able to do this yet.
My plans were to extend the Swift compiler with JSX-like syntax[2] that makes use of the declarative framework. Of course that's still possible, especially now with a canonical "Apple" way of building declarative interfaces in Swift.
I'm a bit sad that with the announcement of SwiftUI my implementation will not stand a chance anymore, but I definitely learned a lot along the way how declarative rendering and reconcilation works in detail.
Bottom line - this is very great news for native app development, declarative UI makes it vastly more easy to reason about code.
[1] https://github.com/PabloSichert/Sx/blob/master/Example/Incre...
As an iOS developer, this is by far the biggest announcement. This has huge potential to provide value to me and my team. I'm looking forward to ripping out programmatic NSLayoutConstraint and Interface Builder from my projects ASAP. This seems like it includes much more than that, however.
Given that SwiftUI has live reloading and a sensible template interface I could absolutely see it winning over some RN devs. There's something to be said (particularly with Apple) for using the native toolset rather than RN, Flutter and the like.
But applications written in React Native aren't cross platform, are they? You have different components depending on the platform. My understanding is that they claimed you wouldn't have to learn a different framework when switching to a new platform, not that your apps would be portable.
At its base React Native provides a common set of native components with the same API on both iOS and Android such as View, Image & Text which can all be styled and laid out through common APIs. These APIs pretty much give you most of what you need to make an entire APP. Sometimes you may want to have different behavior per platfrom and for that you can use the Platform API (provided by React Native) to switch for each platform. This would allow you to do things like change the styling on each platform or the native components you use.
React Native makes it pretty easy to expose native components to JavaScript. It is also up to the native component author if they want to create a common API for all platforms that they support. In the case of Views & styling it makes a lot of sense to have the same API on iOS and Android, but sometimes they are some platform features that are only available on one platform.
Wile Swift Layout is not cross-platform, it may soon be and I think it does a lot for promoting declarative UI & maybe they did take some inspiration from React!
View docs: https://facebook.github.io/react-native/docs/view.html Styling: https://facebook.github.io/react-native/docs/style Layout: https://facebook.github.io/react-native/docs/flexbox
React Native is for cross-platform. SwiftUI is for cross-device.
Does that work?
Even some of the built-in components are platform specific though, such as the segmented control for iOS and view pager for Android. But the nice thing is you don't need to create a separate project to use these, you can just chose the appropriate one at runtime based on the platform.
It works by supplying me with native modules and native components for every platform and I write my domain logic in portable JavaScript.
We get a simple way to make UIs for multiple platforms, we get a nice batteries-included language, and Swift 5.1's dynamic method offers a similar functionality to hot reloading.
Of course, it can't answer everybody's needs (no Windows, Linux, or Android support) but combine SwiftUI with Project Catalyst, and I'm really hoping to see plenty of high-quality cross-platform apps that don't have a whole instance of Chrome underlying them.
Even with other cross-platform offerings like Flutter, React, Electron and so on, getting one codebase to work out of the box on just two platforms can be a challenge. On mobile, there tends to be a need to drop down from the cross-platform stuff to something native for performance reasons — Discord does this for its chat buffer on iOS, Facebook does this for practically everything.
So while people take to their ideological high horses, there'll be people out there who can really benefit from being able to develop for Macs, iPhones, iPads, Apple Watches, and Apple TVs with a single, familiar, and easy yet powerful API to provide a glass of ice water in cross-platform hell.
Did you mean "cross form-factor" or something?
I don't understand how my fellow developers could ever tolerate Apple doing this.
This goes one way, and its been like this for decades.
For a lot of developers, targeting just the Apple platforms is still a worthwhile investment in itself: Apple's customers tend to pay higher prices for quality Mac software — yes, outside the Mac App Store, too — and they will very often be happy to pay for the accompanying iOS app if it's worth doing so.
There have been Apple-only development houses since the year dot and this won't change just because Apple decided to release a platform to make it a little easier for its developers; they're not beholden to the rest of the world and it's ridiculous to believe so.
So if everyone can spend 3,000 dollars and get best in class computing, what are you paying for with Apple?
They have lots of marketing that psychologically makes you feel good?
Not everyone has this urge to create FOSS software, available as free beer in every possible OS out there.
It seems as though they are viewing SwiftUI as a successor to UIKit/AppKit on all their platforms, not just a higher level wrapper.
I bet by next IO, Flutter will get replaced by it, specially after the #KotlinEverywhere announcement and Kotlin/Native effort for iOS.
Trying to sell Dart a 2nd time was a mistake.
I may be missing something, but SwiftUI seems to be pretty much ready to go today.
Which for most companies is 2+ years away
The future of MacOS development is not Marzipan and never was. The future is SwiftUI.
But I think you're right. Catalyst (née Marzipan) is being pitched by Apple as a brilliant way to get a head start on porting iPad apps to the Mac, and should become the best way to write an app that you want both an iPad and Mac version of. But "Mac apps as we know them are dead" always struck me as histrionic, and today's presentation doesn't make me think that any less.
(At least it appears that way, going by the WWDC session descriptions. We'll know more in a couple of hours)
@kylemacomber - can you provide some context here? I'm sure many of us would love to get a high-level understanding of this.
[1] https://blog.iconfactory.com/2019/05/what-to-expect-from-mar...
Then you would get truly native, cross-platform development.
Now, the probability this would ever work is 1%, but it's something that has lingered in my mind anyway.
Flutter targets native code on Android and iOS and JavaScript for the web. It has very mature compilers for all three.
Just no. As an Apple user, just use whatever the tools they give you when you're developing for Apple platforms.
Soon you'll be able to compile SwiftUI to Flutter and reach all platforms it reaches. Their play: to get the best experience, you'd still need to buy an iPhone.
Objective C is much higher than Swift: 11 vs 18.
https://www.tiobe.com/tiobe-index/
This should reverse the rankings and might push Swift into a top 10 language.
And Apache Groovy rose from number 91 to number 17 in the past 12 months also according to that same Tiobe page (May 2019). Quoting Tiobe for anything only discredits what you're trying to prove.
This is one of the things I am eager to get a deep dive on in later session videos.
Syntax aside, there is a large semantic difference between the two: QML is a separate language/modeling tool that is embedded into the application runtime. SwiftUI is in fact ordinary Swift code and the UI you define with it is also ordinary Swift code too, code that XCode and the Swift compiler understand and analyze and refactor and compile like any other. Just with some special magic to make the UI builder work with it. I think this has a lot of advantages notably from a toolchain perspective, since you don't even need XCode (just the Swift compiler) to do things like xrefs/refactorings across SwiftUI code, nor maintain tooling like that across two languages (XYZ + whatever UI modeling language)
Given that, my first impressions of how far they took it (and how well it came out) are pretty good.
I think you might check out more of QML / QtQuick 2 before drawing any conclusions.
import QtQuick 2.12
import QtQuick.Layouts 1.12
ListView {
model: Model.items
delegate: RowLayout {
Image { source: image }
Column {
Text { text: title }
Text {
text: subtitle
color: "gray"
}
}
}
}
This should be more or less the same. Fluid scrolling is backed by the underlying Flickable [1]. RTL support is available an can be changed in runtime [2]. Themes / colors can be changed in runtime as well [3].Lastly, it runs on Windows, Linux and Android as well as OSX and iOS.
[1] https://doc.qt.io/qt-5/qml-qtquick-flickable.html
[2] https://doc.qt.io/qt-5/qtquick-positioning-righttoleft.html
All of these seem somewhat conceptually similar to Audacity ShuttleGUI (https://wiki.audacityteam.org/wiki/ShuttleGui)
Or the Python context-manager-based declarative GUI (wrapping PyQt) I wrote for my relatively small program corrscope (https://github.com/corrscope/corrscope/blob/master/corrscope...)
yes, but it does not prevent you to make desktop apps with it. See e.g. Kirigami UI which is based on QtQuick : https://kde.org/products/kirigami/
(and for "large" desktop apps made with QtQuick, look at the Blizzard launcher, or Substance Designer which is as much a desktop app as one can aspire to be : https://cdn.studiodaily.com/wp-content/uploads/2019/05/subst... )
QML has a fundamental difference with the links you showed : it is able to create bindings according to variables used in expressions / functions / etc.
e.g. if you do
MyWidget {
width: { if(y > 50)
return f(height) + x;
else
return otherItem.height / height;
}
}
then whenever any of the properties used in the expression changes, the width is recomputed.There's something to be said for being able to use one language for all things.
Just a couple examples: you can do Bluetooth discovery scans in QML without writing any C++ [1], you can read from ~20 sensors without writing any C++ [2], you can write complete 3D scenes declaratively in QML [3], and the list goes on.
[1] https://doc.qt.io/qt-5/qml-qtbluetooth-bluetoothdiscoverymod...
sure, and I agree that Swift has some better features and a better foundantion than JS on which QML is based upon
> And you can't write an entire app in QML.
This however is not true. I've worked on multiple pure QML apps so far (well, if you don't count the auto-generated main.cpp). Remember that you have access to a complete ES7 JS engine which allows for a lot of stuff.
This does hurt. I've been programming Objective-C since NeXTSTEP and love it. Swift is still like Perl for me. Something I will use for programming for money, but not enjoy for one minute. I loved the clarity of selector syntax, but Javascript clones rule the world. I still don't understand the love of commas or why they are needed.
Objective c is insanely verbose.
They ditched the selector syntax and went to a Javascript / C++ like syntax. There were so many ways to keep the selector syntax, but they went conformist.
Objective c is insanely verbose.
well, no - Swift's call syntax actually results in the same or more characters:
somePoint.moveBy(x: 2.0, y: 3.0)
[somePoint moveByX: 2.0 y: 3.0];
somePoint.moveBy(x: 2.0, y: 3.0, z: 4.0)
[somePoint moveByX: 2.0 y: 3.0 z: 4.0];
Swift benefited from some shortening of the method names that can be equally applied to Objective-C. Plus, why the whole split by a left parentheses and comma thing?https://developer.apple.com/services-account/download?path=/...
for some reason my account only shows "There’s currently no beta software available for download."
Best-kept secret with direct download links (from apple.com)
>To use the SwiftUI design canvas Xcode 11 must running on macOS Catalina.
Please let us know if you find that's incorrect.
var body: some View {
Wait, what? When was `some` a keyword?Eg. SquareButton and RoundButton are implementations of the Button (protocol).
You want to create a function that returns the button, but you don't want to specify to the user exactly what type of button is it (as it doesn't matter). Your function could just declare the top level protocol as the return type without needed to specify the word "some"
createPlayButton -> Button
instead of createPlayButton -> some Button
Am I missing something? It feels like the 'some' keyword is just there to help the compiler and not the users necessary
it seems like the equivalent of id <MyProtocol> in Objective-C. Basically just a surface re-arranging of names, but keeping the same concepts as in Objective-C
I feel Golang did better in this regards... (eg. not necessary distinguishing between protocols and super class-es, it is quacks like a duck, it is a duck)
The "some" keyword indicates that the function returns a specific type, even if that type isn't known to the caller.
One place where this is meaningful is if you have to use the result of that function in a generic function. For instance if my functions are defined like this:
func createPlayButton() -> Button { ... }
func doSomething<T: Button>(_ button: T) { ... }
And I try to call this: doSomething(createPlayButton())
I will get an error, because the protocol Button does not conform to itself. However If I use opaque types: func createPlayButton() -> some Button { ... }
this works just fine because the compiler is able to determine the concrete type returned by `createPlayButton`https://docs.swift.org/swift-book/LanguageGuide/OpaqueTypes....
This would solve a problem a lot of devs have in deciding how to build a cross platform app. We don’t want to give up first class support for each platform but it’s silly to have completely separate codebases.
I hear even Apple has React Native dev groups.
iOS users update pretty rapidly.
What object is .gray acting on?
.color(UIColor.gray)
https://developer.apple.com/documentation/swiftui/color/3049...
It's also on macOS
For JS/web focused teams I don’t think it impacts much, just like I don’t think this impacts Ionic developers that much.
Airbnb have always been native, and their one foray into partially using React Native didn't work out:
https://medium.com/airbnb-engineering/sunsetting-react-nativ...
I'm interested in your take on that though. I'm self taught and I've got some weird ideas about things.
Meanwhile Android, which yeah only 5% of users or something crazy small are on the latest version, will get to use the latest libraries on versions released 5+ years ago.
Probably still in alpha...
This isn't true at all. Since iOS launched there has been UIKit and then this SwiftUI.
They didn't say anything about iOS. There have been lots of UI frameworks from Apple, some abandoned before they were even finished:
QuickDraw, Quickdraw GX, HIToolbox, AppKit, Cocoa Touch/UIKit, Playgrounds/IB, SwiftUI
The constantly changing frameworks and languages are a useful strategy from platform vendors - they do help provide platform lockin, and make it very very difficult to provide cross platform apps. That is a real threat to Apple with offerings like flutter from Google. Of course there are other reasons to make a clean break with the past, but there is a lot of work just to stand still in developing for a platform like Mac OS or IOS - they don't highly value backwards compatibility and often introduce sweeping changes. Constant change is in the platform vendor's financial interest, and I don't think it's unfair to point that out.
Just to take one example - apps built for the original iOS are now almost entirely obsolete, and it's not worth reusing any of their code in a modern swift app.
Development philosophies change over time, like the other's said, some of those UI frameworks you mentioned are 20+ years old.
It does suck that we can't use it on other platforms, and I'm sure they don't want to spend resources on doing so, but there's no way the main motivation is to keep people switching frameworks constantly.
You're saying that MacOS has been around a long time, which is true.