Skip to content

Instantly share code, notes, and snippets.

@boucher
Created August 23, 2009 21:46
Show Gist options
  • Select an option

  • Save boucher/173468 to your computer and use it in GitHub Desktop.

Select an option

Save boucher/173468 to your computer and use it in GitHub Desktop.
NSManagedObjectContext *context = [XAppDelegate managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Person" inManagedObjectContext:context];
NSArray *XIDsToSearchFor = [person.FriendsXIDs valueForKey:@"intValue"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self IN %@", XIDsToSearchFor];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Rank" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
[fetchRequest setEntity:entity];
[fetchRequest setPredicate:predicate];
//[fetchRequest setFetchLimit:20];
[sortDescriptor release];
[sortDescriptors release];
NSError *error = nil;
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
if (fetchedObjects != nil)
[friendList addObjectsFromArray:fetchedObjects];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment