Better Programming

Advice for programmers.

Member-only story

How To Display Badges in SwiftUI for iOS 15

5 min readJul 23, 2021

--

Phone screen
Photo by Dimitri Karastelev on Unsplash.

At WWDC 2021, Apple announced great new additions and improvements in the third release of SwiftUI. Some of them are big, while others are smaller touches. However, one fact remains true: SwiftUI got a lot better!

Among all the new additions made to that framework, there is one that probably does not sound so important… until we need it — that is, how to show badges in SwiftUI.

Badges aren’t a new concept coming this year. We know and use badges every single day. From the badges with unread emails to the notification badges in third-party applications and badges next to settings in the Settings app, badges have existed for years in iOS and macOS.

What had not existed, however, was the native support for badges in SwiftUI. Prior to its third release, if developers needed to add a badge to an app, then they had to come up with a custom implementation of it. That was a big hassle. Today’s article will demonstrate how to use the new badges API in SwiftUI.

There are a couple of things to note before we can start working with badges. The first is that whatever you will read in this article is available in iOS 15 and above, and on macOS 12 and above (Monterey and up). So, if you were planning to use the new SwiftUI…

--

--

Gabriel Theodoropoulos
Gabriel Theodoropoulos

Written by Gabriel Theodoropoulos

An iOS & macOS app maker writing code in Swift. Author of countless programming tutorials. Content creator. https://serialcoder.dev