TechnologiesSwiftUI

SearchUnavailableContent struct

iOSmacOStvOSwatchOSvisionOSiOS 17.0+✓ renders

A structure that represents the body of a static placeholder search view.

How it works

SearchUnavailableContent is the structure that represents the body of a static placeholder search view — the system's standard "no results" presentation, with its magnifying-glass icon, title, and message. You don't construct it yourself; SwiftUI builds it for you when you reach for ContentUnavailableView.search (or its search(text:) variant), and this type is what fills in the view's Label, Description, and Actions. Its job is to give the empty-search moment the same look and copy people see across the OS, so a query that returns nothing renders a consistent, platform-native state instead of a blank screen. Reach for it indirectly, through ContentUnavailableView.search, wherever a searchable list or grid can come back empty.

  1. Get the content through ContentUnavailableView.search

    You never name SearchUnavailableContent at a call site or call an initializer on it. Instead, the search preset on ContentUnavailableView produces it: the example writes ContentUnavailableView.search(text: "swift ui"), and that static member returns a ContentUnavailableView whose three generic arguments are SearchUnavailableContent.Label, SearchUnavailableContent.Description, and SearchUnavailableContent.Actions.

  2. Pass the query with the text parameter

    The search(text:) form takes the current query string so the placeholder can fold it into its description — phrasing the message around what the person actually typed. Here text: "swift ui" is the value SearchUnavailableContent.Description renders against; in a real app you'd hand it the binding driving .searchable, such as the live search text, so the copy stays in sync with the field.

  3. Prefer the bare search property inside a searchable hierarchy

    There is also a parameterless ContentUnavailableView.search property. When the view sits within a .searchable hierarchy, SwiftUI parses the active query into SearchUnavailableContent.Description automatically, so you don't supply the text yourself. Use search(text:), as the example does, only when you manage the query string outside the standard search environment.

  4. Rely on the nested Label, Description, and Actions views

    SearchUnavailableContent exposes three View-conforming members — SearchUnavailableContent.Label, SearchUnavailableContent.Description, and SearchUnavailableContent.Actions — that compose the icon-and-title, the explanatory line, and any call-to-action area. You don't instantiate these; they're created and laid out for you so the empty-search state matches the system presentation without writing your own Image, Text, or Button.

  5. Treat the result as an ordinary view

    Because the value returned by search(text:) is a ContentUnavailableView built from SearchUnavailableContent, it conforms to View and joins the normal modifier chain. In the example a single .padding() insets the whole placeholder; you'd typically drop it into an .overlay that appears only when your filtered results are empty.

Try it — Change ContentUnavailableView.search(text: "swift ui") to the bare ContentUnavailableView.search to see how SearchUnavailableContent renders its description when no query string is supplied versus when one is.

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.

SearchUnavailableContent.swift
struct SearchUnavailableContentDemo: View {
    var body: some View {
        ContentUnavailableView.search(text: "swift ui")
            .padding()
    }
}
Live preview
No Results
No Results
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →