addressDictionary is deprecated first deprecated in iOS 11.0

3.2k views Asked by At

Just started working on IOS11, moving my code from IOS10.3 into IOS11 has resulted in the following challenge, whereas the following code used to work prior to IOS11:

    CLGeocoder *GeoCoder = [[CLGeocoder alloc] init];
[GeoCoder reverseGeocodeLocation:_LocationManager.location completionHandler:^(NSArray *PlaceMarks, NSError *Error)
 {
     if (!Error)
     {
         MKPlacemark *PlaceMark_MK;

         if (PlaceMarks.count > 0)
         {
             MKPlacemark *PlaceMark = [PlaceMarks objectAtIndex:0];

             if (PlaceMark.location.coordinate.latitude != 0.0F && PlaceMark.location.coordinate.longitude != 0.0F)
             {
                 PlaceMark_MK = [[MKPlacemark alloc] initWithCoordinate:PlaceMark.location.coordinate addressDictionary:PlaceMark.addressDictionary];

....

With IOS11 now, it's complaining about PlaceMark.addressDictionary, whereas, addressDictionary is Deprecated.

addressDictionary' is deprecated: first deprecated in iOS 11.0 - Use @properties

I tried to do that, but unfortunately, the InitWithCoordinate function requires AddressDictionary anyway.

I wonder if anyone had the same problem, I know it's very new (IOS11 just came out yesterday).

2

There are 2 answers

1
Heider Sati On BEST ANSWER

I think I just found the answer anyway:

I replaced the following line:

PlaceMark_MK = [[MKPlacemark alloc] initWithCoordinate:PlaceMark.location.coordinate addressDictionary:PlaceMark.addressDictionary];

with the following line:

PlaceMark_MK = [[MKPlacemark alloc] initWithCoordinate:PlaceMark.location.coordinate postalAddress:PlaceMark.postalAddress];

This seems to resolve this problem.

0
Sanoj Kashyap On

You need to access through properties as below

    var placemark = placemarks[0] as? CLPlacemark
    var address = "\(placemark?.thoroughfare ?? ""), \(placemark?.locality ?? ""), \(placemark?.subLocality ?? ""), \(placemark?.administrativeArea ?? ""), \(placemark?.postalCode ?? ""), \(placemark?.country ?? "")"
        print("\(address)")