Merge pull request #205 from jannon/case-insensitive-orderby

add case-insensitive sortkeys
This commit is contained in:
John Estropia
2017-09-29 19:38:36 +09:00
committed by GitHub

View File

@@ -48,6 +48,16 @@ public enum SortKey {
Indicates that the `RawKeyPath` should be sorted in descending order
*/
case descending(RawKeyPath)
/**
Indicates that the `RawKeyPath` should be sorted in ascending order in a case-insenstive manner
*/
case ascendingInsensitive(RawKeyPath)
/**
Indicates that the `RawKeyPath` should be sorted in descending order in a case-insenstive manner
*/
case descendingInsensitive(RawKeyPath)
}
@@ -124,6 +134,12 @@ public struct OrderBy: FetchClause, QueryClause, DeleteClause, Hashable {
case .descending(let keyPath):
return NSSortDescriptor(key: keyPath, ascending: false)
case .ascendingInsensitive(let keyPath):
return NSSortDescriptor(key: keyPath, ascending: true, selector: #selector(NSString.localizedCaseInsensitiveCompare(_:)))
case .descendingInsensitive(let keyPath):
return NSSortDescriptor(key: keyPath, ascending: false, selector: #selector(NSString.localizedCaseInsensitiveCompare(_:)))
}
}
)