Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot convert value of type '[String : String?]' to expected argument type '[String : AnyObject?]'

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.

like image 610
Adela Toderici Avatar asked Oct 30 '15 13:10

Adela Toderici


1 Answers

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
  }
like image 65
Dharmesh Kheni Avatar answered Oct 12 '22 00:10

Dharmesh Kheni