10 ms·
I’m one of the engineers that spearheaded this initiative inside of Apple. I just wanted to thank the HN community—I’ve been reading HN for 10 years now and it’
by kylemacomber 7y ago
I’m one of the engineers that spearheaded this initiative inside of Apple. I just wanted to thank the HN community—I’ve been reading HN for 10 years now and it’s been formative in my development as a software engineer.
If you’re at WWDC stop by the labs and say hi!
- sdegutis 7y agoHow would you compare this to React.js? In particular, how does SwiftUI approach the concepts that Redux solves [EDIT: in other words, state management]?
- rat9988 7y agoRedux and react are two different questions.
- sdegutis 7y agoWhen people make alternatives to React, at some point they have to address the concept of state changes and side-effects, building in conveniences for it, or leaving it for third parties to develop this area.
- nickbauman 7y ago... Or use something like Reagent where there is language level support for reactive state management using atoms. https://github.com/reagent-project/reagent https://github.com/reagent-project/reagent
- sdegutis 7y agoThat looks like exactly what SwiftUI is doing.
- ng12 7y agoThis has nothing to do with Redux. Redux is about storing global data, nothing more.
- _bxg1 7y ago@State var model = Themes.listModel I haven't tried it out, but the above looks more like MobX: @observable model = new MyListModel();
- ng12 7y agoI think it's a closer analogue to React.useState.
- _bxg1 7y agouseState is for cobbling together state onto what's supposed to be a pure-function. SwiftUI, like MobX (in its normal usage), is class-based and keeps state in a class member.
- ng12 7y agoWhat's the difference between a class and a function with local state? (Semantics aside, either way this behavior is implemented in React via useState or setState, MobX has nothing to do with it)
- _bxg1 7y agoMobX takes normal data (usually class properties) and makes it observable, via an annotation. That very much appears to be what the @State annotation in the Swift code is doing, though I don't know for sure. setState is a totally special container for data; while it technically lives in a class member (this.state), it can only be modified via setState. It isn't observable, so much as setState just internally triggers a render directly. useState is different because your state lives out somewhere in React's core framework, associated with your function only through a value and a callback. It doesn't live in your function's local scope itself, because it would get lost if it did. It's very weird and funky because the whole point of non-class components is for them to be pure functions which have no state. useState is this shortsighted workaround for that self-imposed limitation. Redux, finally, is different because its new states are determined as a pure function of the current state and some change. It's the polar opposite of MobX's mutable-observables pattern. Neither is strictly better, but they're as different as can be.
- baby_wipe 7y agohttps://developer.apple.com/documentation/combine https://developer.apple.com/documentation/combine
- seanalltogether 7y agoLooking over the references and docs, this is pretty much the builder pattern to generate the view tree and data binding to update it.
- jpochtar 7y agoFantastic work you've done here!
- telcy 7y agoThanks. Really good job
- vbezhenar 7y agoIDE support is jaw-dropping. I did not see that kind of integration between text and UI anywhere. Framework code looks like React from the first glance, but IDE integration is game-breaker.
- liuliu 7y agoNew (or kinda new?) Framer X tries to do that for React: https://www.framer.com/development/ https://www.framer.com/development/
- bsaul 7y agoAfter 10 years of following wwdc: you may want to temper your expectations as to what this will truely feels like once this runs on your machine, on a real-size project. 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)
- oflannabhra 7y agoThank you! Looks like your work will impact me (and hundreds of thousands of other developers) every day.
- tigershark 7y agoHi, great work! Is iOS 13 required to use apps made with swift ui?
- anchpop 7y agoThat would be unlikely, as they probably want to support everyone's old apps for a little while at least
- tdiggity 7y agoThank you, this is awesome! I've been hesitant to jump into iOS on my own time. This will push me to build something for fun now.
- vijaybritto 7y agoThis is incredibly awesome! Did you get inspired by the web or by new frameworks like flutter?
- deleted 7y ago[deleted]
- mooman219 7y agoThis looks very similar to Flutter, I wouldn't be surprised if they took some ideas from that which is all well and good; UI construction needs a facelift.
- vijaybritto 7y agoI think if flutter can provide this kind of editor support and experience it would be indispensable for me! Also I'm pretty sure the web would emulate this one pretty soon!
- lucasverra 7y agoswift ui to react !
- gwright 7y agoThat is exactly what I said when I saw the code on the screen. Now if they released a development environment for Android also.... (wishful thinking)
- oakesm9 7y agoIf you mean and official declarative UI library then Google released one of those at Google IO this year: https://developer.android.com/jetpack/compose https://developer.android.com/jetpack/compose
- gwright 7y agoI am very interested in multi-platform Kotlin. I'm not sure how far it will get but on the surface I think it is more likely for Kotlin to work on iOS than Swift on Android. Still learning about compose.
- diffset 7y agoWhere does this leave Storyboards? I can't see complex UI being built in SwiftUI
- divanvisagie 7y agoPeople are using storyboards for complex UI? I was under the impression that people used the more manual processes with larger teams.
- ardit33 7y agoyou are right, not sure why you are being downvoted Almost no large scale app uses storyboards for most of their ui....
- cjf101 7y agoStoryboard references made composing complex UI possible, but IMX there's almost always some breakpoint where it's just less complex to do it with code.
- EdwXD 7y agoyes, my team have been using Storyboard/xib for 99% Auto Layout declaration, PaintCode for rendering custom components (which can be shown directly inside IB), RxSwift/RxCocoa for MVVM
- travisgriggs 7y agoI do a mix. The "program by painting" is great for some things and sucks for other things. Unfortunately, programming UIs entirely by text is terse for some things and incredibly laborious/tedious/boilerplate for others (e.g. doing autolayout in code sucks). 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.
- myko 7y ago
- yonilevy 7y agoThis looks fantastic, congrats! Any word on whether 3rd party IDEs will be able to integrate the live-preview functionality? (AppCode user)
- snuxoll 7y agoI assume AppCode will support this the same way it does with InterfaceBuilder and Storyboards - i.e. it won’t do anything but launch XCode to handle it.
- let_var 7y agoSuper. Declarative UI has been one of the differentiator between native UI development vs say React on the browser. ComponentKit and co. are there but having something official from Apple makes it 10x better! Edit: Also, thank you!
- trevor-e 7y agoLooks very similar to Anko (a Kotlin Android UI DSL). Awesome work, can't wait to try it out.
- Kendos-Kenlen 7y agoIt is. And I think SwiftUI will only push people toward Anko as this kind of libraries/tools will become popular. Also, some concurrence with make both tools even better. That's great news!
- seanalltogether 7y agoDoes this support stylesheet based styling?
- dep_b 7y agoGood question, so far it doesn’t seem so
- sjwright 7y agoAs long as SwiftUI has some support for inheritance and arbitrary variables for all elements like colours, fonts and dimensions, I don't think a stylesheet system would be necessary. 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.
- dimmke 7y agoI just wanted to say thank you - I'm a web developer who has been learning iOS dev in his spare time and made the decision pretty early on to build my views programmatically. 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!
- julius_set 7y agoIf you find iOS / macOS views cumbersome to write programmatically you should feel fortunate you didn’t have to write Android views programmatically.
- lanjoe9 7y agoYou can always create a layout XML file and inflate it. It saves tons of time. I can't imagine why you would do thing in code instead of inflating and attaching them. 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.
- myko 7y agoTrue but who does this? The Android framework isn't built to support that reasonably at all, at least not until Jetpack Compose becomes viable.
- ghoji 7y agoDoes Apple allow employees to post comments like this now? :O I thought they were crazy strict and would, like, fire people for posting on forums or Twitter
- saagarjha 7y agoApple has a set of guidelines for public comments: they don’t restrict employees from commenting publicly entirely, but there are quite a few things they can talk about (such as products that just launched…)
- Grustaf 7y agoWell, why do you think he only posted one comment and then disappeared...
- deleted 7y ago[deleted]
- cuddlybacon 7y agoThis looks fantastic. I work on a little macOS app as a hobby thing, and am excited to try this out!
- sjroot 7y agoI was hoping to hear more discussion about performance. At the root of this seems to be a flexbox-esque implementation in Swift. Yoga, one such flexbox implementation written in C, has touted much better performance over UIKit for a while. How do apps built with SwiftUI compare to their UIKit alternatives? How would it compare with some solutions already in the Swift OSS community that utilize flexbox? [Texture](http://texturegroup.org/ http://texturegroup.org/) comes to mind but I'm sure there are others. It must be so much fun to work on a project that impacts so many developers. Thanks again!
- weberc2 7y agoMinor bit of pedantry--Yoga is written in C++.
- arcatek 7y agoBoth are kinda true - Yoga started as a C library, but was ported over to C++ ~a year and a half ago.
- hellofunk 7y agoIf that’s true, maybe they should update the first paragraph of their github page, which clearly says the library is written in C.
- hellofunk 7y agoYogas github page clearly says that it is implemented in C in the first paragraph.
- weberc2 7y agoIt's wrong. https://github.com/facebook/yoga/tree/master/yoga https://github.com/facebook/yoga/tree/master/yoga
- dep_b 7y agoI'll start wearing tin foil hats again as you built exactly what I had in mind when thought what the future of a Swift-based UI should look like. Literally every box checked.
- cjf101 7y agoThank you to you and your colleagues! I bounce back and forth between web and apple front end dev, and at first glance, this hits a lot of the highlights from both worlds.
- jamanon 7y agoCan I use that in an existing app?
- myko 7y agoOnly if you only support the latest OS versions.
- tekstar 7y agoBack in 2016 we built layer in Swift with a similar goal at Shopify, called FunctionalTableData. FTD's syntax isn't nearly as nice as SwiftUI, but there's many similarities. https://github.com/Shopify/FunctionalTableData 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?
- fontenaut 7y agoI saw somewhere that all this started around 2012.
- pier25 7y agoNice work! 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?
- zachgray 7y agonot all heroes wear capes
- jiyinyiyong 7y agoIf Apple is willing to create a GUI tool for generating the DSL used in SwiftUI, it's not far from enabling UI designers to generate UI by themselves. We may need a lower-level representation for the DSL though. I think it's not a problem that we go one step further and make it happen in the next few years.
- diroussel 7y agoYou could call this hypothetical tool Interface Builder.
- jiyinyiyong 7y agoWatched several short videos, it seems they are already doing that by dragging component to generate code, by configuring parameters in the code with panels. It's very approaching.
- zerr 7y agoIs an imperative API available as well?
- samskiter 7y agoNow you've really given us a dilemma - switch to Flutter or wait and see if SwiftUI goes open source....