mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-31 22:53:04 +02:00
WIP: utilities for clauses
This commit is contained in:
@@ -47,16 +47,6 @@ public struct GroupBy: QueryClause, Hashable {
|
||||
self.init([])
|
||||
}
|
||||
|
||||
/**
|
||||
Initializes a `GroupBy` clause with a list of key path strings
|
||||
|
||||
- parameter keyPaths: a list of key path strings to group results with
|
||||
*/
|
||||
public init(_ keyPaths: [KeyPath]) {
|
||||
|
||||
self.keyPaths = keyPaths
|
||||
}
|
||||
|
||||
/**
|
||||
Initializes a `GroupBy` clause with a list of key path strings
|
||||
|
||||
@@ -68,6 +58,16 @@ public struct GroupBy: QueryClause, Hashable {
|
||||
self.init([keyPath] + keyPaths)
|
||||
}
|
||||
|
||||
/**
|
||||
Initializes a `GroupBy` clause with a list of key path strings
|
||||
|
||||
- parameter keyPaths: a list of key path strings to group results with
|
||||
*/
|
||||
public init(_ keyPaths: [KeyPath]) {
|
||||
|
||||
self.keyPaths = keyPaths
|
||||
}
|
||||
|
||||
|
||||
// MARK: QueryClause
|
||||
|
||||
|
||||
@@ -70,14 +70,9 @@ public enum SortKey {
|
||||
public struct OrderBy: FetchClause, QueryClause, DeleteClause, Hashable {
|
||||
|
||||
/**
|
||||
Initializes a `OrderBy` clause with a list of sort descriptors
|
||||
|
||||
- parameter sortDescriptors: a series of `NSSortDescriptor`s
|
||||
The list of sort descriptors
|
||||
*/
|
||||
public init(_ sortDescriptors: [NSSortDescriptor]) {
|
||||
|
||||
self.sortDescriptors = sortDescriptors
|
||||
}
|
||||
public let sortDescriptors: [NSSortDescriptor]
|
||||
|
||||
/**
|
||||
Initializes a `OrderBy` clause with an empty list of sort descriptors
|
||||
@@ -97,6 +92,16 @@ public struct OrderBy: FetchClause, QueryClause, DeleteClause, Hashable {
|
||||
self.init([sortDescriptor])
|
||||
}
|
||||
|
||||
/**
|
||||
Initializes a `OrderBy` clause with a list of sort descriptors
|
||||
|
||||
- parameter sortDescriptors: a series of `NSSortDescriptor`s
|
||||
*/
|
||||
public init(_ sortDescriptors: [NSSortDescriptor]) {
|
||||
|
||||
self.sortDescriptors = sortDescriptors
|
||||
}
|
||||
|
||||
/**
|
||||
Initializes a `OrderBy` clause with a series of `SortKey`s
|
||||
|
||||
@@ -130,8 +135,6 @@ public struct OrderBy: FetchClause, QueryClause, DeleteClause, Hashable {
|
||||
self.init([sortKey] + sortKeys)
|
||||
}
|
||||
|
||||
public let sortDescriptors: [NSSortDescriptor]
|
||||
|
||||
|
||||
// MARK: FetchClause, QueryClause, DeleteClause
|
||||
|
||||
|
||||
@@ -44,15 +44,20 @@ import CoreData
|
||||
*/
|
||||
public struct Tweak: FetchClause, QueryClause, DeleteClause {
|
||||
|
||||
/**
|
||||
The block to customize the `NSFetchRequest`
|
||||
*/
|
||||
public let closure: (fetchRequest: NSFetchRequest) -> Void
|
||||
|
||||
/**
|
||||
Initializes a `Tweak` clause with a closure where the `NSFetchRequest` may be configured.
|
||||
|
||||
- Important: `Tweak`'s closure is executed only just before the fetch occurs, so make sure that any values captured by the closure is not prone to race conditions. Also, some utilities (such as `ListMonitor`s) may keep `FetchClause`s in memory and may thus introduce retain cycles if reference captures are not handled properly.
|
||||
- parameter customization: a list of key path strings to group results with
|
||||
- parameter closure: the block to customize the `NSFetchRequest`
|
||||
*/
|
||||
public init(_ customization: (fetchRequest: NSFetchRequest) -> Void) {
|
||||
public init(_ closure: (fetchRequest: NSFetchRequest) -> Void) {
|
||||
|
||||
self.customization = customization
|
||||
self.closure = closure
|
||||
}
|
||||
|
||||
|
||||
@@ -60,11 +65,6 @@ public struct Tweak: FetchClause, QueryClause, DeleteClause {
|
||||
|
||||
public func applyToFetchRequest(fetchRequest: NSFetchRequest) {
|
||||
|
||||
self.customization(fetchRequest: fetchRequest)
|
||||
self.closure(fetchRequest: fetchRequest)
|
||||
}
|
||||
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private let customization: (fetchRequest: NSFetchRequest) -> Void
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user