无法将类型“[String : String?]”的值转换为预期的参数类型“[String : AnyObject?]”

Cannot convert value of type '[String : String?]' to expected argument type '[String : AnyObject?]'

我是 Swift 的新手,我遵循了本教程:http://www.raywenderlich.com/90971/introduction-mapkit-swift-tutorial 关于 MapKit。问题是我在这行代码上出错

let placemark = MKPlacemark(coordinate: self.coordinate, addressDictionary: addressDict)

标题中描述了错误。包含这一行的方法是:

func mapItem() -> MKMapItem {
    let addressDict = [String(kABPersonAddressStreetKey): self.subtitle]
    let placemark = MKPlacemark(coordinate: self.coordinate, addressDictionary: addressDict)

    let mapItem = MKMapItem(placemark: placemark)
    mapItem.name = self.title

    return mapItem
}

请帮忙。

您需要将 subtitle 转换为 AnyObject,如下所示:

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

您的完整代码将是:

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
  }