2

I'm looking to show contact thumbnails in my app based on email address, similar to what some mail apps do for email conversations. The images will be shown in a tableview.

I've tried searching the address book and getting a thumbnail for each contact, but it is just too slow to use. I've also already tried lazily loading the image, triggered by cellForRowAtIndexPath, and searching in a background thread in order to not block the main thread. Testing with only about 7,000 contacts, this can take around 30 seconds per contact.

Here is a short gist of the general code - https://gist.github.com/eytanbiala/7456bfcd0c55be056720 Obviously this can be optimized to only load all the contacts once, but for the sake of the question this doesn't matter.

Some users may have up to 100,000 contacts on their device, so this is just way too slow.

One suggestion that has come up is to sync the contacts from the iOS Address Book to the app, and save them in Core Data. Of course, this adds possibly unnecessary complexity to the app.

What is the best way to approach this task?

ebi
  • 4,862
  • 6
  • 29
  • 40
  • It's hard to advise you without knowing how you're going to use these thumbnails, but in general, you should grab the images as you need to display them, not try to get them all at once. This should be similar to lazy loading of images from a server into a table view. There are lots of answers about that on SO. – rdelmar Oct 27 '14 at 16:10
  • I've edited the question to clarify. The images will be shown in cells in a tableview. I've already tried lazily loading the images, it's still too slow to be practical. – ebi Oct 27 '14 at 16:31
  • I don't know why the lazy loading would be too slow. You need to show what you tried, and say how slow it was. – rdelmar Oct 27 '14 at 16:41
  • Ok, updated the original question. – ebi Oct 27 '14 at 18:20
  • You need to show the code you used, not just an explanation. – rdelmar Oct 27 '14 at 19:09
  • Alright, I've added a gist with sample code. – ebi Oct 27 '14 at 19:38
  • @rdelmar I've posted the code, any thoughts? – ebi Oct 28 '14 at 15:14
  • I still can't tell what you're trying to do after looking at that code. Your cellForRowAtIndexPath method doesn't do anything with the cell, and doesn't make use of the indexPath. You also have a method, getAllContacts, and you don't show what you're doing in that method. – rdelmar Oct 28 '14 at 15:29
  • I've updated the code to include that function, which doesn't change anything. If you don't have any ideas, you don't need to comment. – ebi Oct 28 '14 at 15:58
  • If you still can't figure it out what the goal is, you may want to re-read the question. – ebi Oct 28 '14 at 16:03

0 Answers0