I have the following class written in an earlier version of Swift. The Swift 2 Compiler warns that
\'kABPersonAddressStreetKey\' was d
You need to cast your subtitle as AnyObject as shown below:
let addressDict = [String(kABPersonAddressStreetKey): self.subtitle as! AnyObject]
and your complete code for "func mapItem() -> MKMapItem { }" 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
}
You should use:
import Contacts
instead import AddressBook
.CNPostalAddressStreetKey
instead kABPersonAddressStreetKey
.Replace import AddressBook
with import Contacts
and also replace String(kABPersonAddressStreetKey)
with String(CNPostalAddressStreetKey)
import Foundation
import MapKit
import Contacts
class Artwork: NSObject, MKAnnotation {
let title: String?
let locationName: String
let discipline: String
let coordinate: CLLocationCoordinate2D
init(title: String, locationName: String, discipline: String, coordinate: CLLocationCoordinate2D) {
self.title = title
self.locationName = locationName
self.discipline = discipline
self.coordinate = coordinate
super.init()
}
var subtitle: String? {
return locationName
}
// annotation callout info button opens this mapItem in Maps app
func mapItem() -> MKMapItem {
let addressDictionary = [String(CNPostalAddressStreetKey): self.subtitle!]
let placemark = MKPlacemark(coordinate: coordinate, addressDictionary: addressDictionary)
let mapItem = MKMapItem(placemark: placemark)
mapItem.name = title
return mapItem
}
Filed a Radar on this. Got this response today:
Engineering has provided the following information regarding this issue: Please know that you should continue to use the deprecated keys.