Skip to content

Commit 288998d

Browse files
committed
Adding limit parameter to searchFor
1 parent 198be73 commit 288998d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Sources/CoreDataPlus/ManagedObjectSearchable.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,18 @@ public protocol ManagedObjectSearchable where Self: NSFetchRequestResult {
99
}
1010

1111
public extension ManagedObjectSearchable {
12-
static func searchFor(_ predicate: NSPredicate?, sortBy: [NSSortDescriptor]? = nil, context: NSManagedObjectContext) -> [Self] {
12+
static func searchFor(_ predicate: NSPredicate?,
13+
sortBy: [NSSortDescriptor]? = nil,
14+
limit: Int? = nil,
15+
context: NSManagedObjectContext) -> [Self] {
1316
let request = NSFetchRequest<Self>()
1417
request.predicate = predicate
1518
request.entity = entity()
1619

20+
if let limit = limit {
21+
request.fetchLimit = limit
22+
}
23+
1724
if let sortBy = sortBy {
1825
request.sortDescriptors = sortBy
1926
}

0 commit comments

Comments
 (0)