Skip to content

Instantly share code, notes, and snippets.

@sforteln
Created November 17, 2012 01:14
Show Gist options
  • Save sforteln/4092384 to your computer and use it in GitHub Desktop.
Save sforteln/4092384 to your computer and use it in GitHub Desktop.
-(void) addFakeContacts{
ABAddressBookRef addressBook = ABAddressBookCreate();
// create 200 random contacts
for (int i = 201; i < 400; i++)
{
// create an ABRecordRef
ABRecordRef record = ABPersonCreate();
ABMutableMultiValueRef multi = ABMultiValueCreateMutable(kABStringPropertyType);
NSString *email = [NSString stringWithFormat:@"%i@%ifoo.com", i, i];
ABMultiValueAddValueAndLabel(multi, (__bridge CFTypeRef)(email), kABHomeLabel, NULL);
NSString *fname = [NSString stringWithFormat:@"Name %i", i];
NSString *lname = [NSString stringWithFormat:@"Last %i", i];
// add the first name
ABRecordSetValue(record, kABPersonFirstNameProperty, (__bridge CFTypeRef)(fname), NULL);
// add the last name
ABRecordSetValue(record, kABPersonLastNameProperty, (__bridge CFTypeRef)(lname), NULL);
// add the home email
ABRecordSetValue(record, kABPersonEmailProperty, multi, NULL);
// add the record
ABAddressBookAddRecord(addressBook, record, NULL);
}
// save the address book
ABAddressBookSave(addressBook, NULL);
// release
CFRelease(addressBook);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment