我是Swift的新手,我遵循了本教程:http://www.raywenderlich.com/90971/introduction-mapkit-swift-tutorial关于MapKit。问题是我在这行代码上出错了
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
}
错误在标题上描述。包含此行的方法是:
{{1}}
请帮忙。
答案 0 :(得分:14)
您需要将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
}