尝试在Mac上的地址簿中查找联系人时,会显示以下编译器错误“使用未解析的标识符'kABPersonFirstNameProperty'。”我找到了一个适用于iOS的示例here,但找不到与OS X等效的版本。根据文档,我已安装的OS X(10.10.5)版本中提供了ABRecordCopyValue
。
if let book = ABAddressBook.sharedAddressBook() {
let nameIsSmith = ABPerson.searchElementForProperty(kABLastNameProperty, label: nil, key: nil, value: "Smith", comparison: ABSearchComparison(kABEqualCaseInsensitive.rawValue))
let peopleFound = book.recordsMatchingSearchElement(nameIsSmith)
for person in peopleFound {
let firstName = ABRecordCopyValue(book, kABPersonFirstNameProperty).takeRetainedValue() as? String
}
}