<!--
{
  "documentType" : "article",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/Reducing-View-Modifier-Maintenance",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Reducing view modifier maintenance"
}
-->

# Reducing view modifier maintenance

Bundle view modifiers that you regularly reuse into a custom view modifier.

## Overview

To create consistent views, you might reuse the same view modifier or group of modifiers repeatedly across your views.
For example, you might apply the same font and foreground color to many text instances throughout your app, so they all match.
Unfortunately, this can lead to maintenance challenges, because even a small change in format, like a different font size, requires changes in many different parts of your code.

To avoid this overhead, collect a set of modifiers into a single location using an instance of the [`ViewModifier`](/documentation/SwiftUI/ViewModifier) protocol.
Then, extend the [`View`](/documentation/SwiftUI/View) protocol with a method that uses your modifier, making it easy to use and understand.
Collecting the modifiers together provides a single location to update when you want to change them.

### Create a custom view modifier

When you create your custom modifier, name it to reflect the purpose of the collection.
For example, if you repeatedly apply the [`caption`](/documentation/SwiftUI/Font/caption) font style and a secondary color scheme to views to represent a secondary styling, collect them together as `CaptionTextFormat`:

```
struct CaptionTextFormat: ViewModifier {
    func body(content: Content) -> some View {
        content
            .font(.caption)
            .foregroundColor(.secondary)
    }
}
```

Apply your modifier using the [`modifier(_:)`](/documentation/SwiftUI/View/modifier(_:)) method.
The following code applies the above example to a [`Text`](/documentation/SwiftUI/Text) instance:

```
Text("Some additional information...")
    .modifier(CaptionTextFormat())
```

### Extend the view protocol to provide fluent modifier access

To make your custom view modifier conveniently accessible, extend the [`View`](/documentation/SwiftUI/View) protocol with a function that applies your modifier:

```
extension View {
    func captionTextFormat() -> some View {
        modifier(CaptionTextFormat())
    }
}
```

Apply the modifier to a text view by including this extension:

```
Text("Some additional information...")
    .captionTextFormat()
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)