SwiftUI’s Namespace

A property wrapper

Steven Curtis
2 min readOct 3, 2023
Photo by Towfiqu barbhuiya on Unsplash

Difficulty: Beginner | Easy | Normal | Challenging

This article has been developed using Xcode 14.2, and Swift 5.7.2

Prerequisites:

You will be expected to make a Single View SwiftUI Application in Swift.

It would be useful to know something about property wrappers in SwiftUI

Terminology

Property Wrappers: A property wrapper adds a layer of separation between code that manages how a property is stored and the code that defines a property

Motivation

When you think about properties in Swift you usually recognise that they have an explicit type. You know the code, something like:

var myNum: Int

When using type inference you might skip the explicit type and infer it. Something like the following:

var myNum = 3

In SwiftUI the @Namespace property wrapper creates a unique identifier to group and distinguish views or elements within a context.

Why

A namespace identifies views. You might want to do that to ensure animations and transitions are properly coordinated. That is you might use @Namespace to ensure…

--

--

Responses (4)