1

Since ABCreateStringWithAddressDictionary is deprecated in iOS9, what other option is it to get address string from CLGeocoder?

Sebastian L
  • 924
  • 2
  • 10
  • 20
  • If you still support iOS 8 or earlier you won't have any issue using `ABCreateStringWithAddressDictionary`. – rmaddy Sep 23 '15 at 22:45
  • Also see [this answer](http://stackoverflow.com/a/18176732/1226963) for another solution. – rmaddy Sep 23 '15 at 22:48

1 Answers1

0

This is my solution:

let geocoder = CLGeocoder()
geocoder.reverseGeocodeLocation(location, completionHandler: { (placemarks, error) in

                if error != nil {
                    print("Error: \(error?.localizedDescription)")
                }

                if let myMarks = placemarks {
                    if let placemark = myMarks.last {
                        if let addressLine = (placemark.addressDictionary?["FormattedAddressLines"] as? [String]) {
                            self.addressLabel.text = addressLine.joined(separator: ", ")
                        }
                    }
                }
            })

El Key "FormattedAddressLines" return an array with this order: Name, Street, City, State, ZIP, Country. if you print addressLine, you'll see something like this: "Apple Inc., 1 Infinite Loop, Cupertino, CA 95014, United States".

Marlon Ruiz
  • 1,774
  • 16
  • 14