title: IOS/Objective-C: Load one record from Core Data without loading table first
body: <p>For a profile screen, I would like to load the equivalent of a detail page from Core Data without having to load a table first.  I have an entity/ table of multiple users in core data.  But I'm only interested in pulling the profile data on one of them, the current user. I would like to load that directly without going through the process of loading a table and choosing a selection and using path and index row etc.  Once I get the results, I don't want to display them as a row but rather distribute different fields around the page in different elements as you do in a detail page.</p>
  
  <p>Can anyone suggest the best way to do this?</p>
  
  <p>I imagine I need to use a predicate that sorts for the user in question with userid or username.  Ordinarily I use NSFetchedResultsController to perform fetches but perhaps there is a way to do a simpler fetch with executefetchrequest.  Following code is adapted from something I found on SO.  Is it right approach?</p>
  
  <pre><code> - (User *)userInfo:(NSDictionary *)usersList
              inManagedObjectContext:(NSManagedObjectContext *)context
  {
      User *user = nil;
  
      NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Users"];
      request.predicate = [NSPredicate predicateWithFormat:@"username = bob"];
      NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"last" ascending:YES];
      request.sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
  
      NSError *error = nil;
  
      NSArray *matches = [context executeFetchRequest:request error:&amp;error];
  
      if (!matches || ([matches count] &gt; 1)) {
          // handle error
      }  else {
          user = [matches lastObject];
      }
  
      return user;
  }
  </code></pre>