'kABPersonAddressStreetKey' was deprecated in iOS 9.0: use CNPostalAddress.street

后端 未结 4 1552
悲哀的现实
悲哀的现实 2021-02-19 06:43

I have the following class written in an earlier version of Swift. The Swift 2 Compiler warns that

\'kABPersonAddressStreetKey\' was d

相关标签:
4条回答
  • 2021-02-19 07:25

    You need to cast your subtitle as AnyObject as shown below:

    let addressDict = [String(kABPersonAddressStreetKey): self.subtitle as! AnyObject]

    and your complete code for "func mapItem() -> MKMapItem { }" will be:

    func mapItem() -> MKMapItem {
        let addressDict = [String(kABPersonAddressStreetKey): self.subtitle as! AnyObject]
        let placemark = MKPlacemark(coordinate: self.coordinate, addressDictionary: addressDict)
    
        let mapItem = MKMapItem(placemark: placemark)
        mapItem.name = self.title
    
        return mapItem
      }
    
    0 讨论(0)
  • 2021-02-19 07:26

    You should use:

    1. import Contacts instead import AddressBook.
    2. CNPostalAddressStreetKey instead kABPersonAddressStreetKey.
    0 讨论(0)
  • 2021-02-19 07:31

    Replace import AddressBook with import Contacts and also replace String(kABPersonAddressStreetKey) with String(CNPostalAddressStreetKey)

    import Foundation
    import MapKit
    import Contacts
    
    class Artwork: NSObject, MKAnnotation {
    let title: String?
    let locationName: String
    let discipline: String
    let coordinate: CLLocationCoordinate2D
    
    init(title: String, locationName: String, discipline: String,       coordinate: CLLocationCoordinate2D) {
        self.title = title
        self.locationName = locationName
        self.discipline = discipline
        self.coordinate = coordinate
    
        super.init()
    }
    
    var subtitle: String? {
        return locationName
    }
    
    // annotation callout info button opens this mapItem in Maps app
    func mapItem() -> MKMapItem {
        let addressDictionary = [String(CNPostalAddressStreetKey): self.subtitle!]
        let placemark = MKPlacemark(coordinate: coordinate, addressDictionary: addressDictionary)
        let mapItem = MKMapItem(placemark: placemark)
        mapItem.name = title
    
        return mapItem
    
    }
    
    0 讨论(0)
  • 2021-02-19 07:31

    Filed a Radar on this. Got this response today:

    Engineering has provided the following information regarding this issue: Please know that you should continue to use the deprecated keys.

    0 讨论(0)
提交回复
热议问题