Skip to content

Commit d0655c3

Browse files
committed
Add possibility to sort
1 parent 0752694 commit d0655c3

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

FFCoreData/FFCoreData/NSManagedObject+FindAndOrCreate.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ public protocol FindOrCreatable: Fetchable {
6060
static func create(in context: NSManagedObjectContext, applying: KeyObjectDictionary?) throws -> Self
6161

6262
static func find(in context: NSManagedObjectContext, by dictionary: KeyObjectDictionary) throws -> [Self]
63-
static func find(in context: NSManagedObjectContext, with predicate: NSPredicate?) throws -> [Self]
63+
static func find(in context: NSManagedObjectContext, by dictionary: KeyObjectDictionary, sortedBy sortDescriptors: [NSSortDescriptor]) throws -> [Self]
64+
65+
static func find(in context: NSManagedObjectContext, with predicate: NSPredicate?, sortedBy sortDescriptors: [NSSortDescriptor]?) throws -> [Self]
6466

6567
static func findOrCreate(in context: NSManagedObjectContext, by dictionary: KeyObjectDictionary?) throws -> Self
6668
}
@@ -103,9 +105,18 @@ public extension FindOrCreatable {
103105
return try find(in: context, with: dictionary.asPredicate(with: .and))
104106
}
105107

108+
static func find(in context: NSManagedObjectContext, by dictionary: KeyObjectDictionary, sortedBy sortDescriptors: [NSSortDescriptor]) throws -> [Self] {
109+
return try find(in: context, with: dictionary.asPredicate(with: .and), sortedBy: sortDescriptors)
110+
}
111+
106112
public static func find(in context: NSManagedObjectContext, with predicate: NSPredicate?) throws -> [Self] {
113+
return try find(in: context, with: predicate, sortedBy: nil)
114+
}
115+
116+
static func find(in context: NSManagedObjectContext, with predicate: NSPredicate?, sortedBy sortDescriptors: [NSSortDescriptor]?) throws -> [Self] {
107117
let request = fetchRequest()
108118
request.predicate = predicate
119+
request.sortDescriptors = sortDescriptors
109120
return try context.fetch(request)
110121
}
111122

0 commit comments

Comments
 (0)