Instance Property

sortDescriptors

A list of sort descriptors, specifying an order for the fetched objects.

Declaration

var sortDescriptors: [NSSortDescriptor]? { get set }

Discussion

Construct sort descriptors with the properties of the objects that you want to fetch, listed in Table 1. For example, the following code sorts by creation date to find the oldest asset in the photo library.

let fetchOptions = PHFetchOptions()
fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)]
let fetchResult = PHAsset.fetchAssets(with: fetchOptions)
return fetchResult.firstObject

Photos does not support sort descriptors created with the sortDescriptorWithKey:ascending:comparator: method.

See Also

Sorting and Filtering Fetch Results

var predicate: NSPredicate?

A predicate that specifies which properties to select results by and that also specifies any constraints on selection.