-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
50 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 8 additions & 9 deletions
17
Sources/CoreDataPlus/CoreDataCountable.swift → ...CoreDataPlus/ManagedObjectCountable.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,21 @@ | ||
import Foundation | ||
import CoreData | ||
import Foundation | ||
|
||
public protocol CoreDataCountable where Self: NSFetchRequestResult { | ||
public protocol ManagedObjectCountable where Self: NSFetchRequestResult { | ||
init(context: NSManagedObjectContext) | ||
|
||
static func entity() -> NSEntityDescription | ||
static func fetchRequest() -> NSFetchRequest<NSFetchRequestResult> | ||
} | ||
|
||
public extension CoreDataCountable { | ||
static func countFor(_ predicate: NSPredicate?, context:NSManagedObjectContext) -> Int { | ||
|
||
public extension ManagedObjectCountable { | ||
static func countFor(_ predicate: NSPredicate?, context: NSManagedObjectContext) -> Int { | ||
CoreDataLogger.shared.log("counting \(predicate.debugDescription)") | ||
|
||
let request = NSFetchRequest<Self>() | ||
request.predicate = predicate | ||
request.entity = self.entity() | ||
request.entity = entity() | ||
|
||
return (try? context.count(for: request)) ?? 0 | ||
} | ||
} |
37 changes: 18 additions & 19 deletions
37
Sources/CoreDataPlus/CoreDataDeletable.swift → ...CoreDataPlus/ManagedObjectDeletable.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
...ces/CoreDataPlus/CoreDataSearchable.swift → ...oreDataPlus/ManagedObjectSearchable.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import Foundation | ||
import CoreData | ||
import Foundation | ||
|
||
public protocol CoreDataSearchable where Self: NSFetchRequestResult { | ||
public protocol ManagedObjectSearchable where Self: NSFetchRequestResult { | ||
init(context: NSManagedObjectContext) | ||
|
||
static func entity() -> NSEntityDescription | ||
static func fetchRequest() -> NSFetchRequest<NSFetchRequestResult> | ||
} | ||
|
||
public extension CoreDataSearchable { | ||
static func searchFor(_ predicate: NSPredicate?, context:NSManagedObjectContext) -> [Self] { | ||
public extension ManagedObjectSearchable { | ||
static func searchFor(_ predicate: NSPredicate?, context: NSManagedObjectContext) -> [Self] { | ||
let request = NSFetchRequest<Self>() | ||
request.predicate = predicate | ||
request.entity = self.entity() | ||
request.entity = entity() | ||
return (try? context.fetch(request)) ?? [] | ||
} | ||
} |