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

后端 未结 4 1571
悲哀的现实
悲哀的现实 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: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
    
    }
    

提交回复
热议问题