Search SDK for iOS

Search for a location by name or address

This example does not contain a UI. Results will be printed to the Xcode console.

import UIKit
import MapboxSearch
class SimpleListSearchViewController: UIViewController {
let searchEngine = SearchEngine()
// let searchEngine = SearchEngine(accessToken: "<#You can pass access token manually#>")
override func viewDidLoad() {
searchEngine.delegate = self
override func viewDidAppear(_ animated: Bool) {
searchEngine.query = "Mapbox" /// You also can call ` "Mapbox")`
extension SimpleListSearchViewController: SearchEngineDelegate {
func resultsUpdated(searchEngine: SearchEngine) {
print("Number of search results: \(searchEngine.items.count)")
/// Simulate user selection with random algorithm
guard let randomSuggestion: SearchSuggestion = searchEngine.items.randomElement() else {
print("No available suggestions to select")
/// Callback to SearchEngine with choosen `SearchSuggestion` randomSuggestion)
/// We may expect `resolvedResult(result:)` to be called next
/// or the new round of `resultsUpdated(searchEngine:)` in case if randomSuggestion represents category suggestion (like a 'bar' or 'cafe')
func resolvedResult(result: SearchResult) {
/// WooHoo, we retrieved the resolved `SearchResult`
print("Resolved result: coordinate: \(result.coordinate), address: \(result.address?.formattedAddress(style: .medium) ?? "N/A")")
print("Dumping resolved result:", dump(result))
func searchErrorHappened(searchError: SearchError) {
print("Error during search: \(searchError)")
Was this example helpful?