MKMapItem を作成する関数を迅速に記述しようとしていますが、文字列エラーが発生します。コードは次のとおりです。
func mapItem() -> MKMapItem {
let addressDictionary = [String(kABPersonAddressStreetKey): subtitle]
let placemark = MKPlacemark(coordinate: coordinate, addressDictionary: addressDictionary)
let mapItem = MKMapItem(placemark: placemark)
mapItem.name = title
return mapItem
}
を作成しようとすると、次のエラーが発生しましたplacemark
。
型 "[String : String?]" の値を予期される引数型 "[String : AnyObject] に変換できませんか?
完全なクラス コード:
class Bar: NSObject, MKAnnotation {
// MARK: Properties
let id: Int
let title: String
let locationName: String
let url: String
let imageUrl: String
let tags: String
let coordinate: CLLocationCoordinate2D
// MARK: Initialisation
init(id: Int, adress: String, name: String, url: String, tags: String, imageUrl: String, coordinate: CLLocationCoordinate2D) {
// Affectation des attributs
self.id = id
self.title = name
self.locationName = adress
self.url = url
self.imageUrl = imageUrl
self.tags = tags
self.coordinate = coordinate
}
// MARK: Subtitle
var subtitle: String {
return locationName
}
// MARK: Helper
func mapItem() -> MKMapItem {
var addressDictionary : [String:String]?
addressDictionary = [String(kABPersonAddressStreetKey): subtitle]
let placemark = MKPlacemark(coordinate: coordinate, addressDictionary: addressDictionary)
let mapItem = MKMapItem(placemark: placemark)
mapItem.name = title
return mapItem
}
}