Swiftpack.co -  Package - illabo/IIDadata
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
This package provides access to Dadata address suggestions and reverse geocoding APIs
.package(url: "https://github.com/illabo/IIDadata.git", from: "0.2.7")


Version Documentation License

This package provides access to Dadata address suggestions and reverse geocoding APIs.

Basic usage.

try! DadataSuggestions
        apiKey: "<# Dadata API token #>"
        completion: { r in
            switch r {
            case .success(let v):
            case .failure(let e):

There are a bunch of additional init options

Ranging from init with explicit API token.

let dadata = DadataSuggestions(apiKey: "<# Dadata API token #>")

Through init with an API token from Info.plist. But may throw if it's missing.

let dadata = try? DadataSuggestions()

Even to init with check on connectivity. However this init should not be called on main thread as it may take up long time as it makes request to server in a blocking manner. Throws if connection is impossible or request is timed out.

DispatchQueue.global(qos: .background).async {
    let dadata = try? DadataSuggestions(apiKey: "<# Dadata API token #>", checkWithTimeout: 15)

Regardless of the way you init theris more to do with this library

Basic address suggestions request to only search in FIAS database: less matches, state provided address data only.

dadata?.suggestAddressFromFIAS("Тверская обл, Пеновский р-н, деревня Москва"){ print( try? $0.get().suggestions ) }

Basic address suggestions request takes KLADR or FIAS ID as a query parameter to lookup additional data.

dadata?.suggestByKLADRFIAS("9120b43f-2fae-4838-a144-85e43c2bfb29"){ print( try? $0.get().suggestions ) }

However more elaborate queries could be made by providing constraints and/or setting filtering.

var constraint = AddressQueryConstraint()
constraint.region = "Приморский"
constraint.city = "Владивосток"
constraint.country_iso_code = "RU"
constraint.region_iso_code = "RU-PRI"

    "Gogolya 9",
    resultsCount: 5,
    language: .en,
    constraints: [constraint],
    regionPriority: nil,
    upperScaleLimit: .street,
    lowerScaleLimit: .house,
    trimRegionResult: false,
    completion: completion

Or building AddressSuggestionQuery manually. Note in this example it is a query made with FIAS ID instead of free-form text.

let q = AddressSuggestionQuery("9120b43f-2fae-4838-a144-85e43c2bfb29", ofType: .findByID)
q.resultsCount = 1
q.language = .en

dadata?.suggestAddress(q){ try? $0.get().suggestions?.forEach{ print($0) } }

Also reverse geocoding is available.

try? dadata?.reverseGeocode(query: "52.2620898, 104.3203629",
                            delimeter: ",",
                            resultsCount: 1,
                            searchRadius: 100){ r in
                                let v = try? r.get()
                                if let s = v?.suggestions, s.count > 0{
                                    print("\(s[0].value!): LAT#\(s[0].data!.geoLat!) @ LON#\(s[0].data!.geoLon!)")


Project [documentation is available here](https://raw.github.com/illabo/IIDadata/master/ https://illabo.github.io/IIDadata/).


To run the example project, clone the repo, and run pod install from the Example directory first.


IIDadata is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'IIDadata'

Or use Swift PM. Add the following line to your Package.swift file in the dependencies section:

.package(url: "https://github.com/illabo/IIDadata.git", from: "0.2.0")

For contributors

The most convenient way to edit the project is to open Example/IIDadata.xcworkspace in Xcode. It is the workspace of a pod in Cocoapods' terms. It includes not only the IIDadata pod itself, but also an example target with tests. Alternatively you may want to edit IIDadata as Swift PM package. To do so just open Package.swift. Please be aware that the layout in Project Navigator pane would look not the same as if you'd open the xcworkspace. To run XCTestCase you have to create a struct in Tests directory containint your Dadata API token according to example below. The token field would be called during the tests.

struct DadataAPIConstants {
    static let token = "<# Dadata API token #>"



IIDadata is available under the MIT license. See the LICENSE file for more info.


Stars: 0
Last commit: 1 week ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco