DadataSuggestions
public class DadataSuggestions
DadataSuggestions performs all the interactions with Dadata API.
-
New instance of DadataSuggestions.
Required API key is read from Info.plist. Each init creates new instance using same token. If DadataSuggestions is used havily consider
DadataSuggestions.shared()instead.Precondition
Token set with “IIDadataAPIToken” key in Info.plist.Throws
Call may throw if there isn’t a value for key “IIDadataAPIToken” set in Info.plist.Declaration
Swift
public convenience init() throws -
This init checks connectivity once the class instance is set.
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) }Throws
May throw on connectivity problems, missing or wrong API token, limits exeeded, wrong endpoint. May throw if request is timed out.
Declaration
Swift
public convenience init(apiKey: String, checkWithTimeout timeout: Int) throwsParameters
apiKeyDadata API token. Check it in account settings at dadata.ru.
checkWithTimeoutTime in seconds to wait for response.
-
New instance of DadataSuggestions.
Declaration
Swift
public convenience required init(apiKey: String)Parameters
apiKeyDadata API token. Check it in account settings at dadata.ru.
-
Get shared instance of DadataSuggestions class.
Call may throw if neither apiKey parameter is provided nor a value for key “IIDadataAPIToken” is set in Info.plist whenever shared instance weren’t instantiated earlier. If another apiKey provided new shared instance of DadataSuggestions recreated with the provided API token.
Declaration
Swift
public static func shared(apiKey: String? = nil) throws -> DadataSuggestionsParameters
apiKeyDadata API token. Check it in account settings at dadata.ru.
-
Basic address suggestions request with only rquired data.
Declaration
Swift
public func suggestAddress(_ query: String, completion: @escaping (_ result: Result<AddressSuggestionResponse, Error>) -> Void)Parameters
queryQuery string to send to API. String of a free-form e.g. address part.
completionResult handler.
resultresult of address suggestion query.
-
suggestAddress(_:queryType: resultsCount: language: constraints: regionPriority: upperScaleLimit: lowerScaleLimit: trimRegionResult: completion: ) Address suggestions request.
Limitations, filters and constraints may be applied to query.
Declaration
Swift
public func suggestAddress(_ query: String, queryType: AddressQueryType = .address, resultsCount: Int? = 10, language: QueryResultLanguage? = nil, constraints: [AddressQueryConstraint]? = nil, regionPriority: [RegionPriority]? = nil, upperScaleLimit: ScaleLevel? = nil, lowerScaleLimit: ScaleLevel? = nil, trimRegionResult: Bool = false, completion: @escaping (_ result: Result<AddressSuggestionResponse, Error>)->Void)Parameters
queryQuery string to send to API. String of a free-form e.g. address part.
queryTypeLets select whether the request type. There are 3 query types available:
address— standart address suggestion query;fiasOnly— query to only search in FIAS database: less matches, state provided address data only;findByID— takes KLADR or FIAS ID as a query parameter to lookup additional data.resultsCountHow many suggestions to return.
1provides more data on a single object including latitude and longitude.20is a maximum value.languageSuggested results may be in Russian or English.
constraintsList of
AddressQueryConstraintobjects to filter results.regionPriorityList of RegionPriority objects to prefer in lookup.
upperScaleLimitBigger
ScaleLevelobject in pair of scale limits.lowerScaleLimitSmaller
ScaleLevelobject in pair of scale limits.trimRegionResultRemove region and city names from suggestion top level.
completionResult handler.
resultresult of address suggestion query.
-
suggestAddress(_:queryType: resultsCount: language: constraints: regionPriority: upperScaleLimit: lowerScaleLimit: trimRegionResult: completion: ) Address suggestions request.
Allows to pass most of arguments as a strings converting to internally used classes.
Declaration
Swift
public func suggestAddress(_ query: String, queryType: AddressQueryType = .address, resultsCount: Int? = 10, language: String? = nil, constraints: [String]? = nil, regionPriority: [String]? = nil, upperScaleLimit: String? = nil, lowerScaleLimit: String? = nil, trimRegionResult: Bool = false, completion: @escaping (_ result: Result<AddressSuggestionResponse, Error>)->Void)Parameters
queryQuery string to send to API. String of a free-form e.g. address part.
queryTypeLets select whether the request type. There are 3 query types available:
address— standart address suggestion query;fiasOnly— query to only search in FIAS database: less matches, state provided address data only;findByID— takes KLADR or FIAS ID as a query parameter to lookup additional data.resultsCountHow many suggestions to return.
1provides more data on a single object including latitude and longitude.20is a maximum value.languageSuggested results in “ru” — Russian or “en” — English.
constraintsLiteral JSON string formated according to Dadata online API documentation.
regionPriorityList of regions’ KLADR IDs to prefer in lookup as shown in Dadata online API documentation.
upperScaleLimitBigger sized object in pair of scale limits.
lowerScaleLimitSmaller sized object in pair of scale limits. Both can take following values:
country— Страна,region— Регион,area— Район,city— Город,settlement— Населенный пункт,street— Улица,house— Дом,country— Страна,trimRegionResultRemove region and city names from suggestion top level.
completionResult handler.
resultresult of address suggestion query.
-
Basic address suggestions request to only search in FIAS database: less matches, state provided address data only.
Declaration
Swift
public func suggestAddressFromFIAS(_ query: String, completion: @escaping (_ result: Result<AddressSuggestionResponse, Error>) -> Void)Parameters
queryQuery string to send to API. String of a free-form e.g. address part.
completionResult handler.
resultresult of address suggestion query.
-
Basic address suggestions request takes KLADR or FIAS ID as a query parameter to lookup additional data.
Declaration
Swift
public func suggestByKLADRFIAS(_ query: String, completion: @escaping (_ result: Result<AddressSuggestionResponse, Error>) -> Void)Parameters
queryKLADR or FIAS ID.
completionResult handler.
resultresult of address suggestion query.
-
Address suggestion request with custom
AddressSuggestionQuery.Declaration
Swift
public func suggestAddress(_ query: AddressSuggestionQuery, completion: @escaping (_ result: Result<AddressSuggestionResponse, Error>) -> Void)Parameters
queryQuery object.
completionResult handler.
resultresult of address suggestion query.
-
Reverse Geocode request with latitude and longitude as a single string.
Throws
May throw if query is malformed.
Declaration
Swift
public func reverseGeocode(query: String, delimeter: Character = ",", resultsCount: Int? = 10, language: String? = "ru", searchRadius: Int? = nil, completion: @escaping (_ result: Result<AddressSuggestionResponse, Error>)->Void) throwsParameters
queryLatitude and longitude as a string. Should have single character separator.
delimeterCharacter to separate latitude and longitude. Defaults to ‘
,’resultsCountHow many suggestions to return.
1provides more data on a single object including latitude and longitude.20is a maximum value.languageSuggested results in “ru” — Russian or “en” — English.
searchRadiusRadius to suggest objects nearest to coordinates point.
completionResult handler.
resultresult of reverse geocode query.
-
Reverse Geocode request with latitude and longitude as a single string.
Declaration
Swift
public func reverseGeocode(latitude: Double, longitude: Double, resultsCount: Int? = 10, language: QueryResultLanguage? = nil, searchRadius: Int? = nil, completion: @escaping (_ result: Result<AddressSuggestionResponse, Error>)->Void)Parameters
latitudeLatitude.
longitudeLongitude.
resultsCountHow many suggestions to return.
1provides more data on a single object including latitude and longitude.20is a maximum value.languageSuggested results may be in Russian or English.
searchRadiusRadius to suggest objects nearest to coordinates point.
completionResult handler.
resultresult of reverse geocode query.
-
Reverse geocode request with custom
ReverseGeocodeQuery.Declaration
Swift
public func reverseGeocode(_ query: ReverseGeocodeQuery, completion: @escaping (_ result: Result<AddressSuggestionResponse, Error>) -> Void)Parameters
queryQuery object.
completionResult handler.
resultresult of reverse geocode query.
DadataSuggestions Class Reference