RestKit includes a component for easily indexing and searching Core Data entities. It can greatly help in implementing search functionality on a large database. This component is not included by default if RestKit is installed via CocoaPods. So in order to use it, you need to install it as a submodule. Add pod 'RestKit/Search'
to the Podfile
and hit pod install in a terminal.
Before using the indexer, it needs to be configured. You start by importing RestKit/Search.h
headers and adding search indexing for each entity you plan to search:
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel]; // Configure indexing for the Collection entity NSArray *attributesToSearch = @[@"name"]; [managedObjectStore addSearchIndexingToEntityForName:@"Collection" onAttributes:attributesToSearch]; // some code ... [managedObjectStore createManagedObjectContexts]; // Start indexing [managedObjectStore startIndexingPersistentStoreManagedObjectContext...