尝试使用kABPerson属性设置addressDictionary
时出错。我在swift中设置错误吗?
错误:
Use of unresolved identifier 'kABPersonAddress...'
这是代码:
@IBAction func mapButton(sender: AnyObject) {
let coords = CLLocationCoordinate2DMake(40.759212, -73.984632)
let addressDict =
[kABPersonAddressStreet as NSString: "5 main st",
kABPersonAddressCityKey: "New York",
kABPersonAddressStateKey: "NY",
kABPersonAddressZIPKey: "10001"]
let p = MKPlacemark(coordinate:coords, addressDictionary:addressDict)
let mi = MKMapItem(placemark: p)
mi.name = restaurantName // label to appear in Maps app
//let span = NSValue(MKCoordinateSpan:self.map.region.span)
let opts = [
MKLaunchOptionsMapTypeKey: MKMapType.Standard.rawValue,
//MKLaunchOptionsMapSpanKey: span
]
mi.openInMapsWithLaunchOptions(opts)
}
答案 0 :(得分:1)
密钥名称为kABPersonAddressStreetKey
而不是kABPersonAddressStreet
,如果您明确设置了不需要投放密钥的字典类型,那么该密钥名称就是:
let addressDict: [String: String] = [
kABPersonAddressStreetKey: "5 main st",
kABPersonAddressCityKey: "New York",
kABPersonAddressStateKey: "NY",
kABPersonAddressZIPKey: "10001"
]