Main Menu
Lecture 1
Lecture 2
Lecture 4
Lecture 5
Lecture 6
Lecture 7
 

 

 

Change to a qualified and sorted fetch specification

By default records are retreived in the order in which they occur in the database table

Four sort options are available

  1. EOSortOrdering.CompareAscending
  2. EOSortOrdering.CompareDecending
  3. EOSortOrdering.CompareCaseInsensitiveAscending - for Strings
  4. EOSortOrdering.CompareCaseInsensitiveDescending

//create a sort ordering stored in an array
NSMutableArray orderings = new NSMutableArray();
EOSortOrdering order1 = new EOSortOrdering("lastName", EOSortOrdering.CompareCaseInsensitiveAscending
);
orderings.addObject(order1);


// Perform a qualified fetch and sort
//
EOFetchSpecification fetchSpec = new EOFetchSpecification("Student", qual, orderings);
EOEditingContext ec = session().defaultEditingContext();
studentlist = (NSMutableArray)ec.objectsWithFetchSpecification(fetchSpec);

Additional sort orderings are added by adding extra orderings to the array

While it is best to sort as the records are fetched from the database, it can also be done in memory

NSArray sorted = EOSortOrdering.sortedArrayUsingKeyOrderArray(results, orderings);

Sort the names that include "e" in ascending order

Lecture 3 Fetch Demo 3 (Download )

Use EOUtilities to create a fetch specification

A wrapper for common fetches (See the Java Doc for more info)

Tutorial 62 Qualifying Fetch Specifications