ios – 不能将'[String:String?]’类型的值转换为预期的参数类型'[String:AnyObject?]’

前端之家收集整理的这篇文章主要介绍了ios – 不能将'[String:String?]’类型的值转换为预期的参数类型'[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
}

请帮忙.

解决方法

您需要将您的字幕转换为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
  }
原文链接:https://www.f2er.com/iOS/330042.html

猜你在找的iOS相关文章