10
votes

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.

1

1 Answers

15
votes

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
  }