I am trying to save an ABRecordID of an existing contact from the Address Book into Core Data. I have an Int32 defined in my model, but in order to save my object there I need to convert the ABRecordID (which is an Int32) into an NSNumber
Here is my code that converts it:
func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!, didSelectPerson person: ABRecord!, property: ABPropertyID, identifier: ABMultiValueIdentifier) {
let multiValue: ABMultiValueRef = ABRecordCopyValue(person, property).takeRetainedValue()
let index = ABMultiValueGetIndexForIdentifier(multiValue, identifier)
let pickedVal = ABMultiValueCopyValueAtIndex(multiValue, index).takeRetainedValue() as! String
let theRecord = recordIdFromPersonRecord(person)
println(ABRecordGetRecordID(person!))
func recordIdFromPersonRecord (personRecord: ABRecord) -> NSNumber {
let recordId = ABRecordGetRecordID(personRecord)
println(personRecord)
return (NSNumber(int: recordId))
}
This code always prints -1 in the console, no matter what record I select in my address book. I'm a newbie programmer and I'm totally stuck.
Thanks for your help!
EDIT: Commenter below indicated that this is a value reserved for records that do not exist in the address book database...
That is confusing. I am just browsing the AB to get the name value and the ID out of existing records... how can existing records not have a record saved to the address book database? Here is what the definition from the docs is: Records with this ID have not been saved to the Address Book database. Am I misunderstanding?