'AnyObject'不能转换为ABRecordRef

时间:2014-07-17 08:34:32

标签: xcode macos swift

我正试图通过swift从地址簿中获取人们的生日。

    let ab = ABAddressBook.sharedAddressBook()
    var birthday: CFDateRef?       
    for person in ab.people() {
        birthday = ABRecordCopyValue(person, kABBirthdayProperty)
    ...

但是我在xcode中遇到以下错误:

  

AnyObject'无法转换为ABRecordRef

ABRecordCopyValue期望ABRecordRef对象作为第一个参数,但人类的类型为AnyObject。 它也不适用于person as ABRecordRef

1 个答案:

答案 0 :(得分:1)

ABRecordRef与Swift中的ABRecord相同。您应该能够使用ABRecord类中的更简单的API:

for person in ab.people() as [ABPerson] {
    person.valueForProperty(kABBirthdayProperty)...
}