AutocompleteResponse

public class AutocompleteResponse

Represents the response of the Autocomplete Search API, containing a summary and a list of autocomplete results.

autocomplete(options:completion:) uses AutocompleteResponse to encapsulate the results for an autocomplete request.

An example usage of AutocompleteResponse:

let options = AutocompleteOptions(
    query: "mar",
    position: .AMSTERDAM,
    radius: Measurement(value: 100, unit: .kilometers)
)
search.autocomplete(options: options) { result in
    switch result {
    case let .success(response):
        response.results.forEach { result in
            result.segments.forEach { segment in
                switch segment {
                case .brand(let brand):
                    print("\(brand.brand.name) - brand")
                case .poiCategory(let category):
                    print("\(category.poiCategory.name) - category")
                case .plainText(let text):
                    print("\(text.plainText) - plain text")
                @unknown default:
                    print("unknown")
                }
            }
        }
    case let .failure(error):
        print("Handle error: \(error)" )
    }
}

 // Prints:
 //   Market - category
 //   Marqt - brand
 //   Marina - category
 //   Marriott - brand

Lifecycle

  • Creates an AutocompleteResponse with the given parameters.

    Declaration

    Swift

    required public init(summary: AutocompleteSummary, results: [AutocompleteResult] = [])

    Parameters

    summary

    A summary that describes autocomplete request execution.

    results

    The list of results containing autocomplete results.

Public

  • General information about the performed autocomplete request, including the requested phrase and the position around which to prioritize results. You can use it to distinguish what response belongs to what query.

    Declaration

    Swift

    public let summary: AutocompleteSummary
  • List of the results returned by the Autocomplete Search.

    Declaration

    Swift

    public let results: [AutocompleteResult]