File tree Expand file tree Collapse file tree
Sources/CoreDataRepository Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // CoreDataRepository+Custom.swift
2+ // CoreDataRepository
3+ //
4+ //
5+ // MIT License
6+ //
7+ // Copyright © 2024 Andrew Roan
8+
9+ import CoreData
10+ import Foundation
11+
12+ extension CoreDataRepository {
13+ /// Escape hatch method for performing arbitrary operations inside a 'scratchpad' `NSManagedObjectContext` where
14+ /// changes will be discarded if not saved.
15+ public func custom< T> (
16+ schedule: NSManagedObjectContext . ScheduledTaskType = . enqueued,
17+ block: @escaping (
18+ _ parentContext: NSManagedObjectContext ,
19+ _ scratchPadContext: NSManagedObjectContext
20+ ) throws -> T
21+ ) async -> Result < T , CoreDataError > {
22+ await context. performInScratchPad ( schedule: schedule) { [ context] scratchPad in try block ( context, scratchPad) }
23+ }
24+ }
You can’t perform that action at this time.
0 commit comments