[Solved] How to format address lines in Swift?


The address is expressed through the CLPlacemark postalAddress property.

            let address = placemark.postalAddress

That line won’t compile unless you also import Contacts at the top of your file.

Okay, so now you are in the Contacts world! What you have is a CNPostalAddress. You can ask the CNPostalAddress for its street, city, state, and other properties; even better, you can use a CNPostalAddressFormatter to format the address nicely as a multi-line string (which looks like what you’re actually after).

            let f = CNPostalAddressFormatter()
            print(f.string(from: address))

solved How to format address lines in Swift?