<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/searchCompletion(_:)-e0pr",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE16searchCompletionyQrqd__s12IdentifiableRd__lF"
  },
  "title" : "searchCompletion(_:)"
}
-->

# searchCompletion(_:)

Associates a search token with the value of this view when used
as a search suggestion.

```
nonisolated func searchCompletion<T>(_ token: T) -> some View where T : Identifiable
```

## Parameters

`token`

Data to use as the view’s completion.

## Discussion

Use this method to associate a search token with a view that is
within a search suggestion list context. The system uses this value
when the view is selected to replace the partial text being currently
edited of the associated search field.

```
enum FruitToken: Hashable, Identifiable, CaseIterable {
    case apple
    case pear
    case banana

    var id: Self { self }
}

@State private var text = ""
@State private var tokens: [FruitToken] = []

SearchPlaceholderView()
    .searchable(text: $text, tokens: $tokens) { token in
        switch token {
        case .apple: Text("Apple")
        case .pear: Text("Pear")
        case .banana: Text("Banana")
        }
    }
    .searchSuggestions {
        Text("🍎").searchCompletion(FruitToken.apple)
        Text("🍐").searchCompletion(FruitToken.pear)
        Text("🍌").searchCompletion(FruitToken.banana)
    }
```

---

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)