我是Swift的新手,我遵循了此教程:有关MapKit的http://www.raywenderlich.com/90971/introduction-mapkit-swift-tutorial。问题是我在这行代码上出现错误
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
}