#Working with SwiftUI
The Engage iOS SDK also provides some ways to show one or several elements using SwiftUI.
#Engage Observable
You should probably put your Engage instance within an observable object just to be able to pass it through your views as an environment object, like shown below.
ℹ️ The following examples will use that configuration from this point.
#CreateElementView
struct CreateElementView: ViewPresents a single element as a SwiftUI View.
#CreateElement ViewModifier
Presents a single element above an existing view.
func createElement(engage: Engage, slug: String) -> some Viewℹ️ The element view will be put a the top of the modified one. If the element is bigger in height than the view it's printed on, and when using a
wrap layout, the view will automatically resize to the element height.#EngageTarget & AutoCreate
func engageTarget(_ value: String) -> some ViewThis view modifier has to be used when you want to show Engage elements that have a "target" condition.
Simply set the identifier as follow.
func autoCreate(filters: [String] = ["default"])Presents elements on views tagged with the
.engageTarget(_:) method that match the targets.⚠️ If multiple views have the same target value, the element will only be printed in the first matching the value.