Swift
Pattern matching for custom types in Swift
In this post, Natalia demonstrates how to overload the ~=
operator in Swift to implement custom pattern matching for your types.
If you find your switch
statements to be overly complicated, this is worth checking out.
Community Showcase for Swift Packages
ICYMI, the official Swift site has a community showcase for Swift packages, which is hand-curated.
You can nominate your favourite packages via this thread on the Swift forums.
SwiftUI
Add custom dark mode color to your app
It's a well known fact that every app has to support dark mode (and if it doesn't, your users will request it).
In this post, Danijela shows how to define custom colors using an asset catalog, how to reference them using the new asset catalog static properties, and how to apply them to plain View
s, ScrollView
s, as well as List
s and Form
s.
Simple, Clean Empty States in SwiftUI
Displaying empty state (or zero state) is an important aspect of improving the UX of your app, and in this video, Sean goes over how to use the new ContentUnavailableView
in iOS 17 which makes this really easy to implement.
In the spirit of progressive disclosure, the ContentUnavailableView
provide some meaningful defaults that cover the majority of use cases, but you can easily customise it for advanced use cases. Sean goes a bit wild in the last chapter of the video, but it definitely shows how flexible this view is.
I've written about Using View Modifiers to Display Empty State on my blog before, which might still be interesting if your app needs to run on any iOS version below iOS 17.
The craft of SwiftUI API design: Progressive disclosure
Jessie reminded me of this great WWDC presentation.
Building APIs that are easy to use and understand is a challenge. Even if you're a solo developer, working on a side project or just tinkering around, you will notice that the code you wrote yourself feels different from code that an SDK team wrote.
In this talk, Sam Lazarus (who works on the SwiftUI team at Apple) walks us through some key principles for designing APIs that are pleasing to use. Things like considering common use cases, providing intelligent defaults, optimising the call site, and favouring composition sound obvious when you hear them, but Sam not only goes into great detail to show how the SwiftUI team applied them to the code we use on a daily basis, but also how to apply these to your own code.
I love how the entire talk itself progressively reveals the lesson Sam wants us to take away. Well worth watching!
Quick Search with SwiftUI Searchable
Searching is a very common user interaction in many apps (I should know, working at a company that operates a well-known search engine...), and SwiftUI makes implementing search pretty straight forward with the .searchable
view modifier.
Daniel takes it one step further, and demonstrates how to automatically focus the search bar both on iOS and macOS.
Business
App Store Review Guidelines History
Over the years, Apple’s App Store Review guidelines have evolved quite a bit. It’s a lengthy document, and it’s hard to spot the differences. Here is a site that highlights all the recent changes.
Tools
Fonts for Coding
As developers, we stare at our screen for several hours a day (except for when we're waiting for the compiler to finish its work, that is), so we might as well do it in style.
Here is a set of fonts that I've either been using or been intrigued by over the past couple of months, and I'm sharing them here so you can update your coding experience for 2024.
Let me know which one you like best, or share your personal favourite if it's not included!
JetBrains Mono
I've been using JetBrains Mono as my main font in Xcode and other editors for quite some time, and it's the font you also see me use in all of my Firebase videos.
I love the distinctive look its support for ligatures gives to my code.
Monaspace
GitHub announced Monaspace as an innovative superfamily of fonts for code that are designed with the express goal of being used together. For example, you might want to use their Radeon handwriting font for comments or TODO
markers, and the Neon neo-grotesque sans font for everything else.
I've started working on a new color theme for Xcode based on this font family - expect to see it soon in my videos, or when I give a talk.
One thing I find quite amusing is that their playground allows you to select Xcode Dark and Xcode Light color themes, but doesn't offer any Swift (or Objective-C) code snippets.
Commit Mono
Denoted as an anonymous and neutral coding font, Commit Mono aims to create a better reading experience.
Comment
Happy New Year, and welcome to the first issue of Not only Swift in 2024!
I am really looking forward to this year - I've got a bunch of exciting things in the pipeline, and I can't wait to share them with you.
One of those things is this newsletter. As I wrote in the last issue of 2023, when I started it, I decided to keep it going as long as there is growth. Well, the numbers are pointing upwards, so I will definitely keep going!
But I also want to switch things up a bit. Since its beginning, this newsletter has been entirely curated by me - and this isn't going to change! But - I thought it might be nice to give you - my readers - an opportunity to share what you're excited about. So, starting with the next issue, I will include submissions for a new category called Hidden Gems.
To qualify as a true Hidden Gem, a submission should meet the following criteria:
Ready to submit your first Hidden Gem? Fill out this form.
Here's to an exciting 2024!
Peter