Utilities for SwiftUI previews.
A collection of modifiers, views, extensions, and other utilities for building previews in SwiftUI.
Latest documentation: v0.4.1.
See Package Documentation for documentation of earlier versions.
Note
Package documentation is actively being written. Many of the utilities in this package have not been thoroughly documented yet.
Visualize the boundaries, origin, and safe areas of a view, without impacting its layout.
Apply debugOverlay() to a view to overlay the debug
visualization:
Text("Sphinx of Black Quartz")
.font(.title)
Text("Judge my Vow")
.font(.title)
.debugOverlay()See the Debug Overlay documentation for more details.
Visualize the alignment guides of a view, without impacting its layout.
Apply debugAlignmentGuide(_:_:) to overlay a visualization
of the alignment guides:
Text("A new age\ndoes not begin all of a sudden")
.font(.title)
.multilineTextAlignment(.trailing)
.debugAlignmentGuide(.trailingFirstTextBaseline,
.lineWidth(8),
.fixedLength(vertical: 200),
.anchor(.trailing)
)See the Debug Alignment Guide documentation for more details.
Add a floating caption, border, and size information to a view, without impacting its layout.
Apply the floatingCaption(_:_:) modifier to a view to overlay a
floating caption, and optionally draw a border over the owner view:
Circle()
.fill(.tertiary)
.frame(width: 80, height: 80)
.floatingCaption(
"A `Circle` Shape", // caption localized string
.height, // prints the height of the owner view
.alignment(.outerLeadingBottom), // sets the caption alignment
.colorStyle(.indigo), // sets the caption and border color
.borderWidth(4) // sets the border width
)See the Floating Caption documentation for more details.
Other utilities available in this package:
- Several
FormatStyleimplementations for a variety of cases. - The Floating Alignment API for floating content in an overlay.
PreviewCaptionto add a caption to previews that are also easy to read in code.- Several image generators that can be used to produce preview images synchronously and asynchronously with different isolation contexts.
This package is also a catch-all for experimental utilities that do not have an individual project of their own. Some utilities and extensions that will eventually move elsewhere:
- Extension inits for
Slider,Pickerwith support for collections and style formatters. - Extensions for
OptionSetto identify each option through a shift value.
As this package moves towards a 1.0 release, many of these unrelated utilities will move to
separate packages.
Preview Utilities is licensed under the MIT License.
Written with ♥ in San Francisco, California.


