Notification Banner using SwiftUI

Jean-Marc Boullianne

Jean-Marc Boullianne
6 min readDec 1, 2019

Getting Started

Begin by creating a new blank project in Xcode. Select the Single View Template, and make sure you set your project to use SwiftUI.

ViewModifier

Instead of creating a custom SwiftUI View today, we'll be creating a ViewModifier. A ViewModifier From the Documentation, "A modifier that you apply to a view or another view modifier, producing a different version of the original value." Essentially at the end of this, we're going to be able to add a banner to any view we want throughout our app with a single line.

BannerModifier

Start off by creating a new SwiftUI ViewModifier file and name it BannerModifier.swift

Just above the body variable, go ahead and define a new struct called BannerData. Inside define two variables, title and detail. These will be used as the text for your banner.

--

--