下面的课程是用Swift的早期版本编写的。Swift 2编译器警告说
'kABPersonAddressStreetKey‘在iOS 9.0:use CNPostalAddress.street中被否决
并给出一个错误
“无法为类型”MKPlacemark“找到接受类型参数列表的初始化程序”(坐标: CLLocationCoordinate2D,addressDictionary: String :String?)
我意识到选项者需要解决错误,但无论我尝试什么,似乎都解决不了问题。这是由于我是一个新手,迅速和任何帮助,将不胜感激。
import Foundation
import MapKit
import AddressBook
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(kABPersonAddressStreetKey): subtitle]
let placemark = MKPlacemark(coordinate: coordinate, addressDictionary: addressDictionary)
let mapItem = MKMapItem(placemark: placemark)
mapItem.name = title
return mapItem
}
}发布于 2015-06-27 13:47:25
用import AddressBook代替import Contacts,用String(CNPostalAddressStreetKey)代替String(kABPersonAddressStreetKey)
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
}发布于 2016-04-24 21:15:40
你应该使用:
import Contacts而不是import AddressBook。CNPostalAddressStreetKey而不是kABPersonAddressStreetKey。发布于 2016-08-11 01:04:27
在这上面发了雷达。今天收到了这样的答复:
工程提供了有关此问题的下列信息:请知道您应该继续使用废弃的密钥。
https://stackoverflow.com/questions/31085299
复制相似问题