Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 780
alionthego Avatar asked Oct 05 '17 01:10

alionthego


1 Answers

You can get mailing address from CNPostalAddress is like :

CNPostalAddressFormatter.string(from:YOUR_POSTAL_ADDRESS, style: .mailingAddress)
like image 80
Vini App Avatar answered Oct 22 '22 18:10

Vini App