How it works
ContentUnavailableView is a SwiftUI view that presents a standardized empty state: the screen people see when there's no content to show, such as an inbox with no mail, search results that came back empty, or a list waiting on its first item. It gives these moments a consistent, platform-native appearance with a prominent icon, a title, optional explanatory text, and optional call-to-action controls, so you don't have to hand-assemble a stack of Image, Text, and Button views every time. Reach for it wherever a view would otherwise render nothing, and conditionally show it in place of your real content while that content is missing.
Provide the label with a trailing closure
The primary initializer takes a
labelview builder that supplies the emphasized headline at the center of the empty state. ALabelis the natural fit here because it pairs title text with an SF Symbol; in the example the label readsLabel("No Mail", systemImage: "tray.fill"), whichContentUnavailableViewstyles automatically with the large, dimmed icon-over-title treatment.Explain the situation with the description closure
The
descriptionparameter is a second view builder for the secondary line beneath the title, where you tell people why the view is empty and what to expect. Keep it to a short sentence ofText, as inText("New messages you receive will appear here."). It's optional — omit the closure when the label alone is self-explanatory.Offer next steps with the actions closure
The
actionsview builder hosts controls that let people move forward — retry, reload, create the first item, or adjust a filter. HereButton("Refresh") {}carries.buttonStyle(.borderedProminent)so it reads as the primary action.ContentUnavailableViewarranges whatever buttons you place in this closure below the description, and you can leave it out entirely for a purely informational state.Use the search preset for empty results
Beyond the label/description/actions form,
ContentUnavailableViewprovides a built-inContentUnavailableView.searchconfiguration (and asearch(text:)variant) for the common case of a query that returned nothing. It renders the system's standard "no results" presentation, so you get the same magnifying-glass icon and copy users see across the OS without writing your own label.Apply layout and styling modifiers like any view
ContentUnavailableViewconforms toView, so the whole composition participates in the normal modifier chain. In the example a single.padding()insets the entire empty state; you'd typically drop the view into a branch of your layout — swapping it in for your list or grid while the data is absent — and let its centered content fill the available space.
actions: closure containing Button("Refresh") and watch ContentUnavailableView collapse to just the title and description, showing how it adapts to a purely informational empty state.Example & preview
Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.
struct ContentUnavailableViewDemo: View {
var body: some View {
ContentUnavailableView {
Label("No Mail", systemImage: "tray.fill")
} description: {
Text("New messages you receive will appear here.")
} actions: {
Button("Refresh") {}
.buttonStyle(.borderedProminent)
}
.padding()
}
}