I'm new on Swift and I followed this tutorial: http://www.raywenderlich.com/90971/introduction-mapkit-swift-tutorial about MapKit. The problem is that I got an error on this line of code
let placemark = MKPlacemark(coordinate: self.coordinate, addressDictionary: addressDict)
The error is described on title. The method which contains this line is:
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
}
Please help.
You need to cast your subtitle
as AnyObject
as shown below:
let addressDict = [String(kABPersonAddressStreetKey): self.subtitle as! AnyObject]
and your complete code will be:
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With