title: Speed up Core Data fetching
body: <p>This is on iOS.</p>
  
  <p>I have a Core Database with about 350 000 objects. The objects (Product) have two properties: "Barcode" and "Designation". The user can search for an object by searching for the "Barcode", and the "Designation" should be returned. Everything is working fine, except it's slow. The code I use is:</p>
  
  <pre><code>    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:&amp;error];
  
  NSManagedObject *object = [results objectAtIndex:0];
  </code></pre>
  
  <p>Since I only want to fetch one object, is there a way to speed it up? </p>
  
  <p>If I load every object into an Array at the start-up I get a very slow start-up for the app and taking a lot of RAM.</p>
  
  <p>Thanks in advance!</p>
  
  <p>EDIT: I added [fetch setFetchLimit:1]; which speed it up a little bit. But the speed is getting slower the further down in the Database the object is.</p>