跳转至
Structure

EmptyModifier

An empty, or identity, modifier, used during development to switch modifiers at compile time.

Declaration

@frozen struct EmptyModifier : ViewModifier

Overview

Use the empty modifier to switch modifiers at compile time during development. In the example below, in a debug build the Text view inside ContentView has a yellow background and a red border. A non-debug build reflects the default system, or container supplied appearance.

struct EmphasizedLayout: ViewModifier {
    func body(content: Content) -> some View {
        content
            .background(Color.yellow)
            .border(Color.red)
    }
}

struct ContentView: View {
    var body: some View {
        Text("Hello, World!")
            .modifier(modifier)
    }

    var modifier: some ViewModifier {
        #if DEBUG
            return EmphasizedLayout()
        #else
            return EmptyModifier()
        #endif
    }
}
A view containing a text view reading "Hello, World!" and a ViewModifier that returns either an outside custom ViewModifier or EmptyModifier; the custom modifier is applied to the text view, resulting in "Hello, World!" having a yellow background and red outline.

In order to stack multiple modifiers, including the EmptyModifier, see concat(_:)

Availability

iOS 13.0+

macOS 10.15+

tvOS 13.0+

watchOS 6.0+

Topics


Initializer

init() Creates a new modifier that leaves the view unchanged.


Type Property

identity A view modifier that leave the view unchanged.


Type Alias

Body The type of view representing the body.


Instance Method

body(content:) Gets the current body of the caller.