From 825354ef6d11e4e5100817a19436d349c06fd82d Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Sun, 16 Apr 2023 23:05:10 +0200 Subject: [PATCH] Defined the Service public protocol. --- Sources/Persistence/Protocols/Service.swift | 36 +++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Sources/Persistence/Protocols/Service.swift diff --git a/Sources/Persistence/Protocols/Service.swift b/Sources/Persistence/Protocols/Service.swift new file mode 100644 index 0000000..d317459 --- /dev/null +++ b/Sources/Persistence/Protocols/Service.swift @@ -0,0 +1,36 @@ +// +// Service.swift +// Persistence +// +// Created by Javier Cicchelli on 13/04/2023. +// Copyright © 2023 Röck+Cöde. All rights reserved. +// + +import CoreData + +public protocol Service { + + // MARK: Properties + + /// The main managed object context. + var viewContext: NSManagedObjectContext { get } + + // MARK: Functions + + /// Create a private queue context. + /// - Returns: A concurrent `NSManagedObjectContext` context instance ready to use. + func makeTaskContext() -> NSManagedObjectContext + + /// Create a child context of the view context. + /// - Returns: A generated child `NSManagedObjectContext` context instance ready to use. + func makeChildContext() -> NSManagedObjectContext + + /// Save a given context. + /// - Parameter context: A `NSManagedObjectContext` context instance to save. + func save(context: NSManagedObjectContext) + + /// Save a given child context as well as its respective parent context. + /// - Parameter context: A child `NSManagedObjectContext` context instance to save. + func save(childContext context: NSManagedObjectContext) + +}