使用kABPersonAddress属性设置addressDictionary

时间:2015-01-27 05:42:59

标签: objective-c swift

尝试使用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)
}

1 个答案:

答案 0 :(得分:1)

密钥名称为kABPersonAddressStreetKey而不是kABPersonAddressStreet,如果您明确设置了不需要投放密钥的字典类型,那么该密钥名称就是:

let addressDict: [String: String] = [
    kABPersonAddressStreetKey: "5 main st",
    kABPersonAddressCityKey: "New York",
    kABPersonAddressStateKey: "NY",
    kABPersonAddressZIPKey: "10001"
]