- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我用早期版本的 Swift 编写了以下类。 Swift 2 编译器警告
'kABPersonAddressStreetKey' 在 iOS 9.0 中被弃用:使用 CNPostalAddress.street
并报错
'Cannot find an initializer for type 'MKPlacemark' that accepts an argument list of type '(coordinate: CLLocationCoordinate2D, addressDictionary: [String : String?])'
我意识到需要可选值来解决错误,但无论我尝试什么,似乎都无法解决问题。这是因为我是 swift 的新手,我们将不胜感激。
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
}
}
最佳答案
将 import AddressBook
替换为 import Contacts
并将 String(kABPersonAddressStreetKey)
替换为 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
}
关于ios - 'kABPersonAddressStreetKey' 在 iOS 9.0 : use CNPostalAddress. 街道中被弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31085299/
我正在获取地址簿 kABPersonAddressStreetKey 属性。当有多条街道时,值将连接成一个字符串。 [addressDict setObject:self.address.street
我用早期版本的 Swift 编写了以下类。 Swift 2 编译器警告 'kABPersonAddressStreetKey' 在 iOS 9.0 中被弃用:使用 CNPostalAddress.st
我是一名优秀的程序员,十分优秀!