From 53100b202d63b0ce44c2ab7d34b8674a9419a708 Mon Sep 17 00:00:00 2001 From: Jannon Frank Date: Thu, 21 Sep 2017 11:38:29 -0700 Subject: [PATCH] add case-insensitive sortkeys --- Sources/OrderBy.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Sources/OrderBy.swift b/Sources/OrderBy.swift index 862dbda..fb7d5af 100644 --- a/Sources/OrderBy.swift +++ b/Sources/OrderBy.swift @@ -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(_:))) } } )