Go to homepage

Reid Main

  1. Archives
  2. Tags
  3. About Me
  4. Email
  5. Resume

SwiftUI Resources

Software developer has been my job title for over 10 years. In that time I have never really been in on the ground floor for any new technology. Sure I would support the newest version of iOS but things like that were always minor evolutionary steps not massive leaps. Swift was probably my first opportunity to be apart of something like that and I brushed it off because Swift 1.0 really was an insulting release. When Apple announced SwiftUI at WWDC 2019 and I saw some of the on-stage demos I knew this was something I wanted to get involved with.

After looking through all of the WWDC 2019 sessions as well as Apple's official documentation I collated a list of all the resources that I think would be useful to anyone trying to learn SwiftUI.

WWDC 2019

The first place you should look if you want to learn about SwiftUI is WWDC 2019 where it was revealed. Not only do you get to hear from the actual developers who wrote the code, their on-stage demos are always super informative and really help drill home critical points about SwiftUI.

Apple released over 100 videos for WWDC 2019 and I think that 13 of them are useful to someone who wants to learn SwiftUI. After watching these videos I decide to segment them into "required" and "supplementary" groups in the order that I think they should be watched.

Required Videos

These are the seven videos from WWDC 2019 that I think one must watch if they want to learn about SwiftUI.

1. Session 204 - Introducing SwiftUI: Building Your First App

This was Apple's very first session on SwiftUI and it takes you through the process of making an app to book meeting rooms. If you have never worked on an app that uses MVVM or reactive programming this session will be a great primer.

Personally I didn't really learn much because I already had experience with the aforementioned architectures. But it still was useful to watch because it helped me understand Apple's nomenclature and what problems they were trying to solve. By the end I had a dozen or so questions that I wanted to ask and most of them were answered in subsequent videos so it really does get your brain in the correct mindset.

2. Session 216 - SwiftUI Essentials

I hope you're in the mood for avocado toast jokes because you're gonna hear a ton of them while building an app to order some.

This is another solid presentation that lays the foundation for what SwiftUI is. It doesn't really go into detail about anything but it makes sure you get exposed to all the things that SwiftUI can do. From all of the primitive views (Text, Color, Spacer, Image, Shape, Divider) to complex things like the Form view to the dozens of modifiers that you can apply to any of these views. I am honestly shocked that Apple managed to get this much into a v1.

The thing that irked me the most was a slide that described SwiftUI as "the shortest path to a great UI" and I think that is true as long as you want to make your UI look like Apple's. The audience was clapping at every new thing that was demonstrated but all I could keep thinking was "how is my designer going to ask me to customize this?". Maybe I have just worked on too many projects that try to differentiate themselves but all of this "magic" that Apple says they have built sounds like something that is going to be difficult to truly customize outside of basic modifiers like color, font or padding.

3. Session 226 - Data Flow Through SwiftUI

This session is easily one of the most important because it is the only one that goes into detail about how data moves through SwiftUI. Using a podcast app as the backdrop, presenters give detailed examples of how to use the @State and @Binding properties wrappers. They really hammer home the idea of your apps only having a single point of truth and everything else just binds to it. No more having to sync state across multiple views or controllers. "Views are a function of state, not a sequence of events" was one of the key slides from this session.

Another cool thing that was mentioned in this session is that you no longer need to think of external interaction as being different from user interaction. They all boil down to some kind of event that updates your state which will trigger an update of your UI. It doesn't matter if the user tapped on something or a push notification was received. They are just events which affect the state of your app. Nothing more.

4. Session 237 - Building Custom Views with SwiftUI

If you are only going to watch one video from WWDC 2019 make it this one. This session is a prime example of why WWDC is great because the presenters give all sorts of implementation details of SwiftUI that you will probably never see in the official documentation.

For example, they described how the layout engine works. First the parent suggests a size to one of its children. The child then chooses its own size using the parent's suggestion as a guide if it wants. Then the parent places its child into parent's coordinate space as best it can and we repeat until all children have been laid out. Oh they also mentioned that SwiftUI rounds to the nearest pixel so no more subpixel rendering and misaligned images!

There was also a really cool example of how you can sync alignment of child view across different stacks or even write your own alignment strategy using the AlignmentID protocol.

But the best part of this talk was when they got into SwiftUI's drawing model. Unlike UIKit which required you to drop down to CoreGraphics to do custom shapes or paths, SwiftUI's drawing layer is a first class citizen that works right alongside the views. There is essentially no distinction. You can download the sample code from this session which has fantastic examples of custom shapes and drawings.

5. Session 219 - SwiftUI On All Devices

Unless you like listening to someone wax poetically about how tvOS has a different interaction medium you can skip the first 13 minutes of this session. But once you get past that you get to some really cool examples of how you can take an iPhone app and convert it to every other Apple platform. It really showcases how Apple is aiming to take away every little bit of friction that could stop you from porting your app to another platform. After watching this session I actually wanted to make an app that worked everywhere because they did such a great job of showing how easy it was.

6. Session 219 - SwiftUI on watchOS

Even though this session focuses on watchOS there really isn't anything that is truly unique with respect to SwiftUI. Everything that is mentioned in this session you should have seen in a previous video. What makes it special however is that it is just wall-to-wall demos of how you can build something with SwiftUI. Even if you aren't planning on making something for watchOS I still recommend you watch this video to truly understand the versatility of SwiftUI.

7. Session 231 - Integrating SwiftUI

If you're looking to port any of your existing UIKit/AppKit/WatchKit views to SwiftUI you should watch this session. The gist is use a UIViewRepresentable or NSViewRepresentable or WKInterfaceObjectRepresentable to wrap your custom views so that they can be consumed by SwiftUI. It also has a great demo that does in-depth about how you can use BindableObject with your custom views to ensure they update correctly.

Supplementary Videos

Now we get to the six videos from WWDC 2019 that are hard to recommend to everyone because whether you should watch it is completely dependent on your experience.

1. Session 402 - What's New in Swift

I was tempted to remove this session because if you have watched everything that I recommended you've probably already seen most of what this session has to offer. It doesn't really go in-depth on any topics and instead seeds core concepts in your minds so you can go out and find more information about them elsewhere.

2. Session 415 - Modern Swift API Design

Skip the first 13 minutes of this session if you already understand the difference between reference and value types. Skip the next 10 minutes if you already understand protocols and generics. There is a cool example of using an extension on a protocol with a constrained generic to improve code readability so if that interests you definitely give it a watch.

23 minutes into this talk we finally get to the good shit, property wrappers. If you have no idea what those are then you absolutely must watch this talk. Even if you think you have a solid idea I still recommend watching it so you understand why putting $ in front of @State properties in SwiftUI allows you to access bindings. Hint: it involves (dynamic member lookup)(https://github.com/apple/swift-evolution/blob/master/proposals/0195-dynamic-member-lookup.md). You'll also get exposed to a number of the property wrappers that Apple is shipping with Swift 5.1 of which there are a lot.

3. Session 722 - Introducing Combine

"A unified, declarative API for processing values over time"

If that sounds completely alien to you then you should watch this session. If you already have experience with reactive programming I'd still say this is worth a watch because it will get you accustomed to Apple's nomenclature. If you have worked with RxSwift you can also use this handy cheat-sheet from Shai Mishali.

4. Session 721 - Combine in Practice

This builds on the "Introducing Combine" session by going in-depth with a number of examples. Even after you've finished watching this video you'll still have only been exposed to 20% of the classes and operators of the Combine framework. You're going to have to dig into the documentation grok everything that is possible.

5. Session 233 - Mastering Xcode Previews

This is another session is that mostly helpful for all of the demos they give. Little nuggets like you can pin a preview so that when you change files it will persist and automatically update. One interesting implementation detail is that previews do call the application did finish launching method of your app delegate so you should avoid doing intensive work there. This sort of stuff should be offloaded to the new scene delegate. It may also make iPad multitasking easier since your apps move in and out of various states when switching between spaces.

6. Session 238 - Accessibility in SwiftUI

If you are already experienced with accessibility you may be able to skip this session. I was hoping there was going to be something unique about accessibility in SwiftUI but it is pretty much the same as UIKit. They do have a really nice demo where they take a stock SwiftUI app and make it fully accessible that did some things even I was unaware of.

Documentation

Obviously Apple's page for the SwiftUI Framework is the best place to start. It is laid out quite well and has links to core topics such as "Views and Controls", "View Layout and Presentation", "Drawing and Animation" as well as "State and Data Flow". It also references the tutorials for the Landmarks app which I highly recommend everyone go through.

You'll want to make sure you look at the View protocol not just because it is necessary if you want to make a custom view, but for all of the modifiers that can be applied to any view. You'll also want to check out the Shape protocol for all of your custom drawing needs.

If you're going to make use of List views ensure you familiarize yourself with the Identifiable protocol.

Sample Code

Unfortunately Apple has been pretty bad with sample code from WWDC this year and I so far have only been able to find two: Building Custom Views in SwiftUI and Creating Accessible Views.

The Landmarks app tutorials also do have the completed source code attached to them so you can also use that as sample code but I highly recommend you try the tutorials yourself first.