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

前端之家收集整理的这篇文章主要介绍了ios – 不能将'[String:String?]’类型的值转换为预期的参数类型'[String:AnyObject?]’前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是 Swift的新人,我遵循本教程: http://www.raywenderlich.com/90971/introduction-mapkit-swift-tutorial关于MapKit.问题是我在这行代码上有错误
  1. let placemark = MKPlacemark(coordinate: self.coordinate,addressDictionary: addressDict)

错误标题上描述.包含这一行的方法是:

  1. func mapItem() -> MKMapItem {
  2. let addressDict = [String(kABPersonAddressStreetKey): self.subtitle]
  3. let placemark = MKPlacemark(coordinate: self.coordinate,addressDictionary: addressDict)
  4.  
  5. let mapItem = MKMapItem(placemark: placemark)
  6. mapItem.name = self.title
  7.  
  8. return mapItem
  9. }

请帮忙.

解决方法

您需要将您的字幕转换为AnyObject,如下所示:
  1. let addressDict = [String(kABPersonAddressStreetKey): self.subtitle as! AnyObject]

您的完整代码将是:

  1. func mapItem() -> MKMapItem {
  2. let addressDict = [String(kABPersonAddressStreetKey): self.subtitle as! AnyObject]
  3. let placemark = MKPlacemark(coordinate: self.coordinate,addressDictionary: addressDict)
  4.  
  5. let mapItem = MKMapItem(placemark: placemark)
  6. mapItem.name = self.title
  7.  
  8. return mapItem
  9. }

猜你在找的iOS相关文章