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

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

提交回复
热议问题