Skip to content

Instantly share code, notes, and snippets.

@mgratzer
Created February 22, 2021 11:19
Show Gist options
  • Select an option

  • Save mgratzer/171590e718ce4dccb048a98399d0fde4 to your computer and use it in GitHub Desktop.

Select an option

Save mgratzer/171590e718ce4dccb048a98399d0fde4 to your computer and use it in GitHub Desktop.
extension NSSortDescriptor {
/// Usage:
/// NSSortDescriptor(
/// keyPath: \YourType.propertyName,
/// ascending: false
/// )
convenience init<T, U: Any>(keyPath: KeyPath<T, U>, ascending: Bool) {
self.init(
key: NSExpression(forKeyPath: keyPath).keyPath,
ascending: ascending
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment