0

I'm wondering what is the best (fastest and simplest) way to have a textfield auto complete with iPhone's address book contacts information.

Would access the address book each time a key is pressed fast enough ? Or do I have to load everything in my own local database (CoreData typically) ? Another way would be to load everything in memory at each app launch. Any experience regarding the access speed of the adress book ?

ADDED: I'd like to avoid having to load a local copy of the address book content because it's not only more code to write but you also need to sync your local copy when address book is modified.

CodeFlakes
  • 3,671
  • 3
  • 25
  • 28

2 Answers2

2

For super fast character by character retrieval, the approach you need is called a Directed acyclic word graph.

Max MacLeod
  • 26,115
  • 13
  • 104
  • 132
1

Would access the address book each time a key is pressed fast enough ?

Probably not for large books but test it an see. You could call ABAddressBookCopyPeopleWithName with each additional character and see what pops up. You would most likely need to require a minimum number of characters e.g. 3 before performing the search because otherwise you would get a lot of returns for each the first character.

However, I don't think there are functions for phone numbers and addresses.

The alternative would be to create a tree data structure with letters and numbers that would branch out to a leaf containing an ABRecordID of a particular AddressBook entry. Using Core Data relationships is a quick and easy way to do that. Of course, you would have to update your tree continuously.

TechZen
  • 64,370
  • 15
  • 118
  • 145