Building Declarative UI using SWIFTUI

Ok, I have been building Swift applications since the week after Apple introduced it in 2014. During that time I have developed frameworks to simplify GUI creation for macOS, iOS and tvOS. But since I hate the concept of AutoLayout my framework works differently (but well). Frame based control layout is fine for macOS and tvOS, but gets more complex with iPhone/iPad as there are over 14 different device sizes.

So that being said, I figured I’d try an learn SwiftUI for GUI building. I don’t need to learn the “language” part, by this I mean the part NOT related to GUI as I’m guessing that that is 99.99% identical to the standard Swift.

So…..what would be my best course of action? What has anyone done?

Keeping in mind that SwiftUI is not fully baked, I would start with SwiftUI by Example - free quick start tutorials for Swift developers

I’ve also been reading my way through many of Paul Hudson’s books, and I would also recommend Pro SwiftUI – Unleash SwiftUI's full potential

There’s also Auto Layout by Tutorials | Kodeco which looks like a good book that I’m planning to purchase, once I get through my backlog of other material to consume.

Cheers,

1 Like

Hi Dave! I learned SwiftUI by first using an app named DetailsPro to build a prototype of a UI for an app I wanted to build, then examining its generated SwiftUI code, but there was only so much I could do with DetailsPro. Next, I read books on SwiftUI such as Paul Hudson’s books and Big Mountain Studio’s books. I also participated in a web-based course called iPhone Apps 101 by Paul Solt.

But what really got me started was just digging in and building small SwiftUI components in SwiftUI Playgrounds, then combining them in an Xcode project. I was able to get immediate visual feedback about my UI without rebuilding my project — until I added environmental data that persisted across views. The SwiftUI canvas in Xcode couldn’t handle it, so I had to start building the project to see UI changes after that.

1 Like

Thanks… I’ve skimmed a few tutorials, and can’t get past the fact that the common thread seems to to use VStacks, HStacks and ZStacks, which to me just feel like containers that have no real anchor and are a lame replacement for AL. I’m coming from a mind-set where I can put a control on the screen, alter its size based on the device, set it postion based on device etc. And I do not mean a size and postion relative to a template device.

I looked at Hudson’s 100 Days, but the first 50 days seemed to be non-Gui stuff that I already know

Which is why I recommended SwiftUI by Example. It pretty much dives straight into the new UI logic and assumes you already know the Swift language.

There are situations where declarative is not perfect - but in most (of my) cases, it works pretty well. For cross-platform simply very good.

I don’t care about different sizes for iOS devices, just the ‘compact’ and ‘regular’ ‘classes’ ( How to create different layouts using size classes - a free SwiftUI by Example tutorial )

The stacks are imho essential

As for learning:

I prefer Paul Hudsons books and videos (ie ‘hacking…’). Some very good stuff comes from ‘swiftfull thinking’ (Nick Sarno), other things are explained perfect by Sean Allen (he’s the one who said ‘don’t try to get everything in Your head’). So, I’m using a mix. I got a pro version of Youtube, just because of my learnings…

There are others with very good tutorials, but as a first place, I check Paul Hudsons stuff and Nick Sarno for principles

4 Likes

I found this book useful: Amazon.com

It assumes you already know Swift. It’s 2+ years old now, but it’s hard to find books that are any more current.

I can also recommend the video tutorials by Karin Prater: https://www.youtube.com/@SwiftyPlace

3 Likes