Heider Sati
Heider Sati

Reputation: 2614

addressDictionary is deprecated first deprecated in iOS 11.0

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).

Upvotes: 2

Views: 3330

Answers (2)

Sanoj Kashyap
Sanoj Kashyap

Reputation: 5060

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)")

Upvotes: 0

Heider Sati
Heider Sati

Reputation: 2614

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.

Upvotes: 2

Related Questions