Normalize a Street Address in Swift

2 min readJun 16, 2021


When retrieving user information, such as addresses, from text strings in electronic correspondence, incompatible formatting is a common occurrence. To avoid this potential issue, you can use the following API to automatically normalize and validate an input street address; it supports all major international addresses, ensuring full coverage of your customer base.

All you will need for this operation is your parse request (full address) and API key, which you can input into the below example code:

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
var semaphore = DispatchSemaphore (value: 0)let parameters = "{\n \"StreetAddress\": \"<string>\",\n \"City\": \"<string>\",\n \"StateOrProvince\": \"<string>\",\n \"PostalCode\": \"<string>\",\n \"CountryFullName\": \"<string>\",\n \"CountryCode\": \"<string>\"\n}"
let postData = .utf8)
var request = URLRequest(url: URL(string: "")!,timeoutInterval: Double.infinity)
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("YOUR-API-KEY-HERE", forHTTPHeaderField: "Apikey")
request.httpMethod = "POST"
request.httpBody = postData
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
print(String(data: data, encoding: .utf8)!)

The returned response will indicate if the address is valid, as well as the latitude and longitude if it is. To retrieve your API key, visit the Cloudmersive website and register for a free account; this provides 800 monthly calls across any of our APIs.




There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.