The direct answer to your question is no. Your best option, with your current design is to do them in an operation but then you have the thread barrier to worry about and slow you down. Keep in mind that if your operations are not running on the main thread then you need a separate NSManagedObjectContext
for the operation or you are going to run into threading issues.
Better question: Why are you doing a new fetch for each character?
If you already have the fetch results from a previous search and the user did not remove a character, just take the existing results and run your predicate against the NSArray
. That will further refine the search instead of going to disk each time. Since it is in memory it will be extremely fast.
Consider the following options when implementing a search field:
- Hit the disk only on the first character
- Hit the disk only if a character is deleted from the search box
- Consider preloading the objectID and the searchable property to avoid disk hits.
Depending on what you are searching (and there are ways to renormalize the Core Data store to improve searching) you can preload quite a bit into memory. Even with 42K records if the search properties are small enough you can load them all into memory.
Chances are you need to test for that use case anyway if the user starts with pressing "A".
What part of the NSFetchRequest
is slow? Hitting the SQLite database or loading the data into memory? Based on your answer you can improve the search performance directly.