Getting full address string from CLPLacemark using Swift 4 / Xcode 9

3.8k views Asked by At

I have previously been able to get a full address String from a CLPlacemark using the following code for Swift 3:

let addressList = placemark.addressDictionary?["FormattedAddressLines"] as? [String]
let address =  addressList!.joined(separator: "\n")

addressDictionary is now deprecated in swift 4.

I could extract each of the individual CLPlacemark address variable strings (name, country postalCode, etc) but I'm wondering if there is a simpler way to do it.

I know there is a postalAddress var which is of type CNPostalAddress but not sure how to convert that to a String.

1

There are 1 answers

1
Vini App On BEST ANSWER

You can get mailing address from CNPostalAddress is like :

CNPostalAddressFormatter.string(from:YOUR_POSTAL_ADDRESS, style: .mailingAddress)