View profile

🔥 Combine, async/await, and Property Wrappers - Not Only Swift - Issue #18

Peter Friese
Peter Friese
👋🏻 Hi everyone!
I am super excited about this year - we’ve got so many things planned for you, I literally can’t wait to tell you all about it!
But first things first - in this issue, I’ve got a bunch of articles from my blog (which I completely rebuild using Publish, by the way), as well as some pretty cool articles from around the community. 
If you like the newsletter, share it with a friend by email, and if you haven’t done so already, follow me on Twitter.
Thanks for reading,
Peter 🔥

What I am working on
In previous issues of the newsletter I mentioned that I started working on migrating my blog from Gatsby to Publish. After a (short) period of testing, I decided to flip the switch and push to production.
I give you -, built entirely with Publish!
There are a couple of custom features, for example:
  • I can link to a GitHub repo by adding the repo URL (and the tag/branch info) to an article’s frontmatter
  • It’s possible to call out individual sections in the code samples (using numbers, borders, and background highlighting)
  • I can turn blockquotes into beautiful boxes by using some special markup
  • Related articles will automatically be added to the end of an article
I’ve got a lot more ideas I am going to implement over the next couple of weeks, and I am super happy with how easy this is with Publish.
If you’re interested in learning how I built this, and how I host this (hint: Firebase Hosting), vote on this poll on Twitter!
In other news, I’ve started a new series about how to access the network using Combine. So far, I’ve published two posts in this series:
  1. Networking with Combine and SwiftUI - Getting Started
  2. Optimise your networking layer with Combine - Efficient networking for SwiftUI apps
The third article (about error handling) is in the queue, but it had to make way for an important topic that is a source of confusion for many developers who are getting started with Firebase:
How to call asynchronous Firebase APIs?
(Almost) all of Firebase’s APIs are asynchronous, which might be a little confusing for people who are new to this programming model. After all, the SDKs make it appear as if your calls are happening locally - at least at first sight. Once you look closer, you realise that most calls will involve a network call (and thus inherently be asynchronous). 
On StackOverflow, we get a decent number of questions about how to call Firebase APIs on iOS every week, so I thought I’d write up all the ways you can call Firebase APIs asynchronously in a nice article: Calling asynchronous Firebase APIs from Swift - Callbacks, Combine, and async/await
If you’re interested in the TL;DR:, check out this Twitter thread.
Whether or not you should use external dependencies in your applications is a frequently discussed topic among iOS developers. As part of the Firebase team I am obviously biased, but I personally like to explore what’s out there. In the past, I used to use to search and discover SDKs and libraries, but ever since moving to Swift Package Manager, this isn’t a viable option any more. Searching on GitHub resembled finding the proverbial needle in the hackstack. Wouldn’t it be great to have a service for discovering Swift Packages? It turns out there’s not just one, but at least three of them - so which one should you use? Here is Marco Eidinger with a great overview of the Swift Package Registry, the Swift Packge Index, and His conclusion might surprise you!
What happens when your application starts a long-running process (such as downloading a large file), and then the user decides they want to download a different file? Or the user starts typing a search query, and then updates the filter criteria. These are everyday situations in our apps, and Combine makes it easy to solve them with just one line of code. Learn how to use the switchToLatest operator to discard the previous request in this article by Moritz Philip Recke.
There are three different ways in SwiftUI to build depth-stacked view hierarchies: background, overlays, and the ZStack. But which one should you use? John Sundell explains their respective properties. As always, John’s article provides some really deep insights into new APIs, along with some code to backport this to previous iOS versions. But see for yourself!
Property wrappers are a powerful feature of the Swift language, and they play a key role in SwiftUI: Its entire state management system is exposed via property wrappers, making it a lot easier for us to build UIs in SwiftUI. But how do property wrappers work under the hood - specificallym, how can a property wrapper trigger a view update in SwiftUI? Donny Wals wrote an excellent deep dive to explain all of this. BTW, this is how we built the @FirestoreQuery property wrapper that allows you to fetch data from a Firestore collection with just a single line of code.
And finally...
Prince of Persia in JavaScript!
Did you enjoy this issue? Yes No
Peter Friese
Peter Friese @peterfriese

Xcode tips & tricks, Swift, SwiftUI, Combine, Firebase, computing and internet history, and - of course - some fun stuff.

In order to unsubscribe, click here.
If you were forwarded this newsletter and you like it, you can subscribe here.
Created with Revue by Twitter.