lukagabric / LargeDatasetSample

iOS Large Dataset Sample - Core Data and NSFetchedResultsController with search (like Contacts in Phone application)
http://lukagabric.com/large-dataset-sample-core-data-and-nsfetchedresultscontroller-with-search/
11 stars 4 forks source link

Why not use NSFetchedResultsController to filter content ? #1

Open onmyway133 opened 10 years ago

onmyway133 commented 10 years ago

Hi, your solution works OK. Especially in the _filteredResults to cache the search results

But I think there are 2 problem here

  1. _filteredResults will be full very quickly as user search for a long time (in one opening UISearchBar)
  2. In filterContentForSearchText() why not use NSFetchedResultsController?
lukagabric commented 10 years ago

Hi,

I've checked the utilized memory and as far as I can tell the memory is not an issue for the set of 50,000 items. I'm not using NSFetchedResultsController for filtering because I couldn't get it to perform as fast as this method with a dictionary. This way I always perform filtering on the subset of items. I believe FRC always performs the fetch request on the entire set.

Please do let me know of the issues you've found regarding the _filteredResults. Also, what do you think about using FRC for filtering, as I've tried it and could not get results that come close to this solution?

Regards, Luka.

onmyway133 commented 10 years ago

With the FRC approach, I would use 2 FRCs (1 for Main TableView and 1 for Search TableView), just like this answer http://stackoverflow.com/a/4481896/1418457

With every search text changed, I create new Search FRC, set Predicate for it. So "I believe FRC always performs the fetch request on the entire set" is not a problem

As you may know, FRC first fetches the IDs only, then fetches only 20 (batchSize) items. So memory usage is more efficient

But I don't know if creating FRC many times causes any bad effects (like cache cleaning, memory cleanup time...)

lukagabric commented 10 years ago

In my previous comment I was referring to the second (search) FRC, I have used two FRCs before I implemented the dictionary approach. The problem with the search FRC was that for each letter I input in the search field it took the same amount of time to display data, obviously for each input letter you would expect the results to show up much faster. For each input a fresh fetch is performed since the FRC is being recreated with cache deleted. It took way too long for the results to be displayed after entering a letter on the 50,000 items dataset.