Skip to content

Commit

Permalink
Adding limit parameter to searchFor
Browse files Browse the repository at this point in the history
  • Loading branch information
spnkr committed Jan 3, 2023
1 parent 198be73 commit 288998d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Sources/CoreDataPlus/ManagedObjectSearchable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ public protocol ManagedObjectSearchable where Self: NSFetchRequestResult {
}

public extension ManagedObjectSearchable {
static func searchFor(_ predicate: NSPredicate?, sortBy: [NSSortDescriptor]? = nil, context: NSManagedObjectContext) -> [Self] {
static func searchFor(_ predicate: NSPredicate?,
sortBy: [NSSortDescriptor]? = nil,
limit: Int? = nil,
context: NSManagedObjectContext) -> [Self] {
let request = NSFetchRequest<Self>()
request.predicate = predicate
request.entity = entity()

if let limit = limit {
request.fetchLimit = limit
}

if let sortBy = sortBy {
request.sortDescriptors = sortBy
}
Expand Down

0 comments on commit 288998d

Please sign in to comment.