Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSPredicate to fetch records in alphabetical order in CoreData

I am trying to fetch records from an Entity, the records are huge above 5000. So i want to fetch the records with alphabetically sorted(name paramter) instead of sorting with NSSortDescriptor on result array.

Is there any predicate we can place to fetech records alphabetically sorted.

like image 438
Sudheer Kumar Palchuri Avatar asked Dec 11 '22 03:12

Sudheer Kumar Palchuri


1 Answers

Set the NSSortDecriptor within your NSFetchRequest *fetchRequest, like you would with any predicate

[fetchRequest setSortDescriptors:@[[[NSSortSDescriptor alloc] initWithKey:@"name parameter" ascending:YES]]];

This means your request is already sorted like you require as it's being fetched.

As Kaszas has already said, an NSPredicate isn't for sorting, it's for filtering

Hope this helps

like image 193
Jim Tierney Avatar answered Dec 29 '22 00:12

Jim Tierney