> ## Documentation Index
> Fetch the complete documentation index at: https://docs.baato.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Swift

> Integrate the Baato API into iOS projects with the official Swift client.

BaatoSwift wraps the Baato API in completion-handler methods that return Swift `Result`
values, so success and failure are handled in one `switch`.

<Columns cols={2}>
  <Card title="Podspec on GitHub" icon="github" href="https://github.com/baato/BaatoPodSpec" horizontal>
    `baato/BaatoPodSpec`
  </Card>

  <Card title="Turn-by-turn example" icon="apple" href="/examples/ios/turn-by-turn" horizontal>
    Navigation in an iOS app.
  </Card>
</Columns>

## Installation

BaatoSwift is distributed as a CocoaPod from Baato's own spec repository. Add both the
source and the pod to your `Podfile`:

```ruby theme={null}
source 'https://github.com/baato/BaatoPodSpec.git'

target '${YourApp}' do
  use_frameworks!

  pod 'BaatoSwift', '~> ${LatestVersion}'
end
```

Then run:

```bash theme={null}
pod install
```

<Note>
  Replace `${LatestVersion}` with the current version from the
  [podspec repository](https://github.com/baato/BaatoPodSpec).
</Note>

## Creating a client

Initialise once with your access token, then set the parameters for each request as
properties before calling the matching method.

```swift theme={null}
let baatoClient = BaatoSwift.API.init(token: "YOUR_BAATO_ACCESS_TOKEN")
```

## Usage

<AccordionGroup>
  <Accordion title="Search — place suggestions" icon="magnifying-glass" defaultOpen>
    ```swift theme={null}
    // searchQuery is a required parameter
    baatoClient.searchQuery = "SearchQuery"

    // optional parameters
    // number of results to return
    baatoClient.searchLimit = 10

    // latitude and longitude coordinates, for providing additional geographical context to the search.
    baatoClient.searchLat= 27.7172
    baatoClient.searchLon= 85.3240

    // The type or category of results that the request should return. For example: hospital, cafe etc.
    baatoClient.searchType= "hospital"

    // radius, in kilometers from the specified lat/lon pair within which to look for results. Only integer values supported.
    baatoClient.searchRadius= 50

    // Perform the search
    baatoClient.getSearch { (result) in
                    switch result {
                    case .success(let data):
                    // response is a [SearchResult]?
                    print(data?.first?.address, data?.first?.address)
                        guard let data = data else {
                            return
                        }
                    case .failure(let error):
                        print(error)
                    }
    }
    ```
  </Accordion>

  <Accordion title="Reverse Search — coordinates to an address" icon="location-crosshairs">
    ```swift theme={null}
    // reverseLat and reverseLon are required parameters
    baatoClient.reverseLat = latitude
    baatoClient.reverseLon = longitude

    // Perform the reverse search request
    baatoClient.getReverse {  (result) in
                    switch result{
                    case .success(let data):
                      // response is a Place object
                      print(data?.address, data?.name)
                    case .failure(let error):
                        print(error)
                    }
    }
    ```
  </Accordion>

  <Accordion title="Places — full detail for a place ID" icon="location-dot">
    ```swift theme={null}
    // placeId is a required parameter
    baatoClient.placeId = placeId

    // Perform the place lookup
    baatoClient.getPlaces {  (result) in
                    switch result{
                    case .success(let data):
                      // response is a Place object
                      print(data?.address, data?.name)
                    case .failure(let error):
                        print(error)
                    }
    }
    ```
  </Accordion>

  <Accordion title="Directions — routes between points" icon="route">
    ```swift theme={null}
    // startLat, startLon, destLat, destLon, navMode are all required parameters
    baatoClient.startLat = 27.73405
    baatoClient.startLon = 85.33685
    baatoClient.destLat = 27.7177
    baatoClient.destLon = 85.3278

    // Mode is the vehicle profile, specified is an enum with the following values: bike, car and foot
    baatoClient.navMode = BaatoSwift.NavigationMode.bike

    // specify if you need alternative routes (only supports two points), or instructions to be included in your response
    baatoClient.navAlternatives = false
    baatoClient.navInstructions = true

    // Perform the directions request
    baatoClient.getDirections {(result) in
                    switch result{
                    case .success(let data):
                      // response is a Navigation Response object
                      print(data?.first?.distanceInMeters, data?.first?.timeInMs)
                    case .failure(let error):
                        print(error)
                    }
    }
    ```

    <Note>
      `timeInMs` is milliseconds, not seconds. See
      [core concepts](/about/concepts#encoded-polylines).
    </Note>
  </Accordion>
</AccordionGroup>

## Next

<Columns cols={2}>
  <Card title="Turn-by-turn navigation" icon="diamond-turn-right" href="/examples/ios/turn-by-turn">
    A complete navigation implementation.
  </Card>

  <Card title="Map Styles API" icon="layer-group" href="/services/styles">
    Style URLs for MapLibre and Mapbox on iOS.
  </Card>
</Columns>
