Files
Termind/Frameworks/TermindPersistence/ModelContext+Commit.swift
T

20 lines
405 B
Swift

import SwiftData
@MainActor
extension ModelContext {
public func savePendingChanges() throws {
try commit {}
}
public func commit(beforeSave: () throws -> Void = {}, _ operation: () throws -> Void) throws {
do {
try operation()
try beforeSave()
try save()
} catch {
rollback()
throw error
}
}
}