What I am working on
SwiftUI: Custom Validation Handling
The fourth part of Building SwiftUI Components is out! Did you ever wonder how onDelete, onAppear or task are implemented? These methods allow developers to register actions on views that will be executed at certain times. In this episode, we look at how to implement an action handler that will be called to perform custom validation logic.
I also published the source code for this and all previous episodes of the series.
Firebase
It's been a while...
As I mentioned previously, we are cooking up some really exciting things at Firebase. A lot of our work happens out in the open, so if you follow our repositories closely, you might be able to get some ideas of what to expect in the coming weeks and months. Oh, and today, the official @Firebase account tweeted this:
Verified email addresses
We’ve gotten used to treating our email addresses as sort of a unique identifier, but they come with a number of challenges. For example, when a user signs up to your app using email and password authentication, you should perform an email validation. For example, to make sure the user didn’t accidentally (or deliberately) misspell their email address. It’d be pretty upsetting for them if they need to reset their password, but the password reset email never arrives in their inbox.
Firebase Authentication treats email addresses as verified if the user completed the Firebase verification flow, or if the email has been verified by a trusted Identity Provider. Some IdPs allow their users to change their email address without re-verification - these are considered untrusted. To learn more about this, read the documentation.
Run code samples directly in the Google Cloud documentation
The Google Cloud team added an easy way to launch a Cloud Shell right from the documentation. No need to set up a test project to try a cool new feature you discovered in the docs - just jump into the Cloud Shell - without leaving the page.
Swift
Swift 5.5. Released
Swift 5.5 is now officially released. Most of us will get it together with Xcode 13, but if you’re on a non-macOS platform, you can get the toolchain from the downloads section on Swift.org.
The blog post highlights the impressive list of Swift Evolution proposals that made it into version 5.5, and you will find that most of them revolve around Swift’s new concurrency model.
If you haven’t had time to dive into Swift’s new concurrency model, there are a number of options to get up to speed:
- Watch all the WWDC 2021 videos about concurrency. If you need a viewing guide, check out this thread.
- Read Andy Ibanez’ excellent article series
The Actor Reentrancy Problem in Swift
Actors are an important concept in Swift’s new concurrency model - they help us write code that is free from data races and deadlocks. If you’ve watched Apple’s WWDC videos closely, you will remember they mentioned that “Actor reentrancy prevents deadlocks and guarantees forward progress, but it requires you to check your assumptions across each await.” Here is Lee Kah Seng with a real-world example that nicely highlights the problem, and two strategies to handle it.
Syntax: if case let
In a piece of code I wrote for this PR, I wanted to use if case let , but - I am sure you can relate - I didn’t know the syntax by heart. Not to worry - https://goshdarnifcaseletsyntax.com/ had me covered.
It turned out that our linter had a different opinion on which syntax to use, so we had a little fight about whether to use if case .success(let fruits) = fruitResults
or if case let .success(fruits) = fruitResults
…
What’s your preferred way to do pattern matching in Swift?
Productivity
Reading Code is a Skill
Trisha Gee dives into a discussion whether you should get good at reading code or write more readable code. She makes some very good points, and I’ve found myself thinking about some of the aspects of readable code recently. As a content creator, I want to make sure the code I present in my videos and articles is easy to understand for my audience, and helps to transport the concepts I want to talk about. At the same time, I want to write code in an efficient and idiomatic way. The bottom line, as Trisha puts it in her article, is reading code is a skill. The more code you read, the better you get at it. And with so much of the code out there being open source, there really is no shortage of great material!
Podcasts
At the beginning of the pandemic, I established a fake commute to make sure I get enough exercise and don’t just walk between my bed, the kitchen, and my desk. To keep me entertained, I started listening to podcasts. Hundreds, even thousands of them. One of the series I enjoyed very much is Land of the Giants by Recode. In previous seasons, they covered Amazon, Netflix, Google, and the delivery economy. In the upcoming season, Land of the Giants: The Apple Revolution, Recode’s Peter Kafka will explore the company that changed what a computer is — and then changed what a phone is. Check it out!
Comment
Hello!
Is it just me, or does it feel like time is flying? Maybe it’s the constant drumbeat of product announcements and releases - last week, Apple announced new hardware (did you (pre-)order anything?), and this week, they officially released Swift 5.5. And - of course - iOS 15 has been released, and if the excitement and buzz on Twitter is anything to go by, many developers have updated their apps to support the new APIs on day one!
The year isn’t over yet, and I am sure we will see even more exciting product announcements and launches in the remaining months of 2021. I hope you enjoy this fourth edition of Not Only Swift Weekly - if you do, please share it with a friend. And as always, feel free to share your feedback with me!
Thanks for reading!
Peter