This is on iOS.
I have a base database with about 350,000 objects. Objects (Product) have two properties: "Barcode" and "Designation". The user can search for an object by searching for "Barcode", and "Designation" must be returned. Everything is working fine, except for the slow ones. The code I'm using is:
NSEntityDescription *_product = [NSEntityDescription entityForName:@"Product" inManagedObjectContext:importContext];
NSFetchRequest *fetch = [[NSFetchRequest alloc]init];
[fetch setEntity:_product];
[fetch setPredicate:[NSPredicate predicateWithFormat:@"Barcode == %@",theBarcode]];
NSError *error = nil;
NSArray *results = [importContext executeFetchRequest:fetch error:&error];
NSManagedObject *object = [results objectAtIndex:0];
Since I only want to get one object, is there a way to speed it up?
If I load each object into an array at startup, I get a very slow startup for the application and consuming a lot of RAM.
Thanks in advance!
EDIT: I added [fetch setFetchLimit: 1]; that speed it up a bit. But the speed slows down the further the object is in the database.