From 326b897b06b54caba5bb779a7e5df6b6a2ac12ee Mon Sep 17 00:00:00 2001 From: John Estropia Date: Sat, 19 Oct 2019 09:34:31 +0900 Subject: [PATCH] WIP: docs --- .../CollectionViewDemoViewController.swift | 4 +- .../ColorsDemo.swift | 8 +- .../ListObserverDemoViewController.swift | 4 +- .../SwiftUI Demo/SwiftUIView.swift | 13 +- Sources/AsynchronousDataTransaction.swift | 15 + Sources/BaseDataTransaction.swift | 18 + ...edDiffableDataSourceSnapshotDelegate.swift | 47 ++- Sources/ListPublisher.swift | 8 +- Sources/ListSnapshot.swift | 347 +++++++++++++----- Sources/SynchronousDataTransaction.swift | 15 + 10 files changed, 354 insertions(+), 125 deletions(-) diff --git a/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/CollectionViewDemoViewController.swift b/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/CollectionViewDemoViewController.swift index 362ab99..abc664f 100644 --- a/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/CollectionViewDemoViewController.swift +++ b/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/CollectionViewDemoViewController.swift @@ -67,7 +67,7 @@ final class CollectionViewDemoViewController: UICollectionViewController { case UICollectionView.elementKindSectionHeader: let view = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "PaletteCollectionSectionHeaderView", for: indexPath) as! PaletteCollectionSectionHeaderView - view.label?.text = ColorsDemo.palettes.sectionIdentifiers[indexPath.section] + view.label?.text = ColorsDemo.palettes.snapshot.sectionIDs[indexPath.section] return view default: @@ -110,7 +110,7 @@ final class CollectionViewDemoViewController: UICollectionViewController { self.performSegue( withIdentifier: "ObjectObserverDemoViewController", - sender: ColorsDemo.palettes[indexPath: indexPath] + sender: ColorsDemo.palettes.snapshot[indexPath] ) } diff --git a/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ColorsDemo.swift b/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ColorsDemo.swift index 931aa0b..daff9e5 100644 --- a/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ColorsDemo.swift +++ b/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ColorsDemo.swift @@ -45,9 +45,11 @@ struct ColorsDemo { didSet { - self.palettes.refetch( - self.filter.whereClause(), - OrderBy(.ascending(\.hue)) + try! self.palettes.refetch( + From() + .sectionBy(\.colorName) + .where(self.filter.whereClause()) + .orderBy(.ascending(\.hue)) ) } } diff --git a/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ListObserverDemoViewController.swift b/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ListObserverDemoViewController.swift index 14f614f..3df9d0e 100644 --- a/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ListObserverDemoViewController.swift +++ b/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ListObserverDemoViewController.swift @@ -23,7 +23,7 @@ final class ListObserverDemoViewController: UITableViewController { switch editingStyle { case .delete: - let palette = ColorsDemo.palettes[indexPath: indexPath] + let palette = ColorsDemo.palettes.snapshot[indexPath] ColorsDemo.stack.perform( asynchronous: { (transaction) in @@ -122,7 +122,7 @@ final class ListObserverDemoViewController: UITableViewController { self.performSegue( withIdentifier: "ObjectObserverDemoViewController", - sender: ColorsDemo.palettes[indexPath: indexPath] + sender: ColorsDemo.palettes.snapshot[indexPath] ) } diff --git a/CoreStoreDemo/CoreStoreDemo/SwiftUI Demo/SwiftUIView.swift b/CoreStoreDemo/CoreStoreDemo/SwiftUI Demo/SwiftUIView.swift index 8b727cd..33706ca 100644 --- a/CoreStoreDemo/CoreStoreDemo/SwiftUI Demo/SwiftUIView.swift +++ b/CoreStoreDemo/CoreStoreDemo/SwiftUI Demo/SwiftUIView.swift @@ -23,20 +23,23 @@ struct SwiftUIView: View { var body: some View { NavigationView { List { - ForEach(palettes.sectionIdentifiers, id: \.self) { (sectionID) in + ForEach(palettes.snapshot.sectionIDs, id: \.self) { (sectionID) in Section(header: Text(sectionID)) { - ForEach(self.palettes[section: sectionID], id: \.self) { palette in + ForEach(self.palettes.snapshot.items(inSectionWithID: sectionID), id: \.self) { palette in NavigationLink( destination: DetailView(palette: palette), label: { ColorCell(palette: palette) } ) } .onDelete { itemIndices in - let objectsToDelete = self.palettes[section: sectionID, itemIndices: itemIndices] + let objectIDsToDelete = self.palettes.snapshot.itemIDs( + inSectionWithID: sectionID, + atIndices: itemIndices + ) self.dataStack.perform( asynchronous: { transaction in - transaction.delete(objectsToDelete) + transaction.delete(objectIDs: objectIDsToDelete) }, completion: { _ in } ) @@ -44,7 +47,7 @@ struct SwiftUIView: View { } } } - .navigationBarTitle(Text("SwiftUI (\(palettes.numberOfItems) objects)")) + .navigationBarTitle(Text("SwiftUI (\(palettes.snapshot.numberOfItems) objects)")) .navigationBarItems( leading: EditButton(), trailing: HStack { diff --git a/Sources/AsynchronousDataTransaction.swift b/Sources/AsynchronousDataTransaction.swift index 3c926fb..988e337 100644 --- a/Sources/AsynchronousDataTransaction.swift +++ b/Sources/AsynchronousDataTransaction.swift @@ -109,6 +109,21 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { return super.edit(into, objectID) } + /** + Deletes the objects with the specified `NSManagedObjectID`s. + + - parameter objectIDs: the `NSManagedObjectID`s of the objects to delete + */ + public override func delete(objectIDs: S) where S.Iterator.Element: NSManagedObjectID { + + Internals.assert( + !self.isCommitted, + "Attempted to delete an entities from an already committed \(Internals.typeName(self))." + ) + + super.delete(objectIDs: objectIDs) + } + /** Deletes the specified `NSManagedObject`s or `CoreStoreObject`s represented by series of `ObjectRepresentation`s. diff --git a/Sources/BaseDataTransaction.swift b/Sources/BaseDataTransaction.swift index 2d44fe4..08879d8 100644 --- a/Sources/BaseDataTransaction.swift +++ b/Sources/BaseDataTransaction.swift @@ -154,6 +154,24 @@ public /*abstract*/ class BaseDataTransaction { ) return self.fetchExisting(objectID) } + + /** + Deletes the objects with the specified `NSManagedObjectID`s. + + - parameter objectIDs: the `NSManagedObjectID`s of the objects to delete + */ + public func delete(objectIDs: S) where S.Iterator.Element: NSManagedObjectID { + + Internals.assert( + self.isRunningInAllowedQueue(), + "Attempted to delete an entity outside its designated queue." + ) + let context = self.context + objectIDs.forEach { + + context.fetchExisting($0).map(context.delete(_:)) + } + } /** Deletes the specified `NSManagedObject`s or `CoreStoreObject`s represented by series of `ObjectRepresentation`s. diff --git a/Sources/Internals.FetchedDiffableDataSourceSnapshotDelegate.swift b/Sources/Internals.FetchedDiffableDataSourceSnapshotDelegate.swift index 7098e2d..3a06159 100644 --- a/Sources/Internals.FetchedDiffableDataSourceSnapshotDelegate.swift +++ b/Sources/Internals.FetchedDiffableDataSourceSnapshotDelegate.swift @@ -119,13 +119,15 @@ extension Internals { var snapshot = Internals.DiffableDataSourceSnapshot( sections: controller.sections ?? [] ) - snapshot.reloadItems(self.reloadedIDs) + snapshot.reloadSections(self.reloadedSectionIDs) + snapshot.reloadItems(self.reloadedItemIDs) self.handler?.controller( controller, didChangeContentWith: snapshot ) - self.reloadedIDs.removeAll() + self.reloadedItemIDs.removeAll() + self.reloadedSectionIDs.removeAll() } @objc @@ -139,14 +141,45 @@ extension Internals { @objc dynamic func controller(_ controller: NSFetchedResultsController, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) { - - let object = anObject as! NSManagedObject - self.reloadedIDs.append(object.objectID) + + switch type { + + case .update, + .move where indexPath == newIndexPath: + let object = anObject as! NSManagedObject + self.reloadedItemIDs.append(object.objectID) + + case .insert, + .delete, + .move: + return + + @unknown default: + return + } + } + + func controller(_ controller: NSFetchedResultsController, didChange sectionInfo: NSFetchedResultsSectionInfo, atSectionIndex sectionIndex: Int, for type: NSFetchedResultsChangeType) { + + switch type { + + case .update: + self.reloadedSectionIDs.append(sectionInfo.name) + + case .insert, + .delete, + .move: + return + + @unknown default: + return + } } // MARK: Private - - private var reloadedIDs: [NSManagedObjectID] = [] + + private var reloadedItemIDs: [NSManagedObjectID] = [] + private var reloadedSectionIDs: [String] = [] } } diff --git a/Sources/ListPublisher.swift b/Sources/ListPublisher.swift index b992aa4..4f14329 100644 --- a/Sources/ListPublisher.swift +++ b/Sources/ListPublisher.swift @@ -279,11 +279,6 @@ public final class ListPublisher: Hashable { sectionBy: sectionBy, applyFetchClauses: applyFetchClauses ) - - try newFetchedResultsController.performFetchFromSpecifiedStores() - - newFetchedResultsControllerDelegate.handler = self - self.query = ( from: from, sectionBy: sectionBy, @@ -291,6 +286,9 @@ public final class ListPublisher: Hashable { applyFetchClauses: applyFetchClauses ) (self.fetchedResultsController, self.fetchedResultsControllerDelegate) = (newFetchedResultsController, newFetchedResultsControllerDelegate) + + newFetchedResultsControllerDelegate.handler = self + try newFetchedResultsController.performFetchFromSpecifiedStores() } deinit { diff --git a/Sources/ListSnapshot.swift b/Sources/ListSnapshot.swift index fd2723e..ffda6c9 100644 --- a/Sources/ListSnapshot.swift +++ b/Sources/ListSnapshot.swift @@ -175,18 +175,18 @@ public struct ListSnapshot: RandomAccessCollection, Hashable { - returns: `true` if at least one object in any section exists, `false` otherwise */ - public func hasObjects() -> Bool { + public func hasItems() -> Bool { return self.diffableSnapshot.numberOfItems > 0 } /** - Checks if the `ListSnapshot` has at least one object the specified section. + Checks if the `ListSnapshot` has at least one object in the specified section. - - parameter section: the section index. Using an index outside the valid range will return `false`. + - parameter sectionIndex: the section index. Using an index outside the valid range will return `false`. - returns: `true` if at least one object in the specified section exists, `false` otherwise */ - public func hasObjects(in sectionIndex: Int) -> Bool { + public func hasItems(inSectionIndex sectionIndex: Int) -> Bool { let snapshot = self.diffableSnapshot let sectionIDs = snapshot.sectionIdentifiers @@ -198,138 +198,141 @@ public struct ListSnapshot: RandomAccessCollection, Hashable { return snapshot.numberOfItems(inSection: sectionID) > 0 } + /** + Checks if the `ListSnapshot` has at least one object the specified section. + - parameter sectionID: the section identifier. Using an index outside the valid range will return `false`. + - returns: `true` if at least one object in the specified section exists, `false` otherwise + */ + public func hasItems(inSectionWithID sectionID: SectionID) -> Bool { + let snapshot = self.diffableSnapshot + guard snapshot.sectionIdentifiers.contains(sectionID) else { + return false + } + return snapshot.numberOfItems(inSection: sectionID) > 0 + } - - + /** + The number of items in all sections in the `ListSnapshot` + */ public var numberOfItems: Int { return self.diffableSnapshot.numberOfItems } + /** + The number of sections in the `ListSnapshot` + */ public var numberOfSections: Int { return self.diffableSnapshot.numberOfSections } - public var sectionIdentifiers: [SectionID] { + /** + Returns the number of items for the specified `SectionID`. + + - parameter sectionID: the `SectionID`. Specifying an invalid value will raise an exception. + - returns: The number of items in the given `SectionID` + */ + public func numberOfItems(inSectionWithID sectionID: SectionID) -> Int { + + return self.diffableSnapshot.numberOfItems(inSection: sectionID) + } + + /** + Returns the number of items at the specified section index. + + - parameter sectionIndex: the index of the section. Specifying an invalid value will raise an exception. + - returns: The number of items in the given `SectionID` + */ + public func numberOfItems(inSectionIndex sectionIndex: Int) -> Int { + + let snapshot = self.diffableSnapshot + let sectionID = snapshot.sectionIdentifiers[sectionIndex] + return snapshot.numberOfItems(inSection: sectionID) + } + + /** + All section identifiers in the `ListSnapshot` + */ + public var sectionIDs: [SectionID] { return self.diffableSnapshot.sectionIdentifiers } - public var itemIdentifiers: [ItemID] { + /** + Returns the `SectionID` that the specified `ItemID` belongs to, or `nil` if it is not in the list. + + - parameter itemID: the `ItemID` + - returns: the `SectionID` that the specified `ItemID` belongs to, or `nil` if it is not in the list + */ + public func sectionID(containingItemWithID itemID: ItemID) -> SectionID? { + + return self.diffableSnapshot.sectionIdentifier(containingItem: itemID) + } + + /** + All object identifiers in the `ListSnapshot` + */ + public var itemIDs: [ItemID] { return self.diffableSnapshot.itemIdentifiers } - public func numberOfItems(inSection identifier: SectionID) -> Int { + /** + Returns the item identifiers belonging to the specified `SectionID`. - return self.diffableSnapshot.numberOfItems(inSection: identifier) + - parameter sectionID: the `SectionID`. Specifying an invalid value will raise an exception. + - returns: the `ItemID` array belonging to the given `SectionID` + */ + public func itemIDs(inSectionWithID sectionID: SectionID) -> [ItemID] { + + return self.diffableSnapshot.itemIdentifiers(inSection: sectionID) } - public func itemIdentifiers(inSection identifier: SectionID) -> [ItemID] { + /** + Returns the item identifiers belonging to the specified `SectionID` and a `Sequence` of item indices. - return self.diffableSnapshot.itemIdentifiers(inSection: identifier) - } + - parameter sectionID: the `SectionID`. Specifying an invalid value will raise an exception. + - parameter indices: the positions of the itemIDs to return. Specifying an invalid value will raise an exception. + - returns: the `ItemID` array belonging to the given `SectionID` at the specified indices + */ + public func itemIDs(inSectionWithID sectionID: SectionID, atIndices indices: S) -> [ItemID] where S.Element == Int { - public func itemIdentifiers(inSection identifier: SectionID, atIndices indices: IndexSet) -> [ItemID] { - - let itemIDs = self.diffableSnapshot.itemIdentifiers(inSection: identifier) + let itemIDs = self.diffableSnapshot.itemIdentifiers(inSection: sectionID) return indices.map({ itemIDs[$0] }) } - public func sectionIdentifier(containingItem identifier: ItemID) -> SectionID? { + /** + Returns the index of the specified `ItemID` in the whole list, or `nil` if it is not in the list. - return self.diffableSnapshot.sectionIdentifier(containingItem: identifier) + - parameter itemID: the `ItemID` + - returns: the index of the specified `ItemID`, or `nil` if it is not in the list + */ + public func indexOfItem(withID itemID: ItemID) -> Index? { + + return self.diffableSnapshot.indexOfItem(itemID) } - public func indexOfItem(_ identifier: ItemID) -> Index? { + /** + Returns the index of the specified `SectionID`, or `nil` if it is not in the list. - return self.diffableSnapshot.indexOfItem(identifier) + - parameter sectionID: the `SectionID` + - returns: the index of the specified `SectionID`, or `nil` if it is not in the list + */ + public func indexOfSection(withID sectionID: SectionID) -> Int? { + + return self.diffableSnapshot.indexOfSection(sectionID) } - public func indexOfSection(_ identifier: SectionID) -> Int? { - - return self.diffableSnapshot.indexOfSection(identifier) - } - - public mutating func appendItems(_ identifiers: [ItemID], toSection sectionIdentifier: SectionID? = nil) { - - self.diffableSnapshot.appendItems(identifiers, toSection: sectionIdentifier) - } - - public mutating func insertItems(_ identifiers: [ItemID], beforeItem beforeIdentifier: ItemID) { - - self.diffableSnapshot.insertItems(identifiers, beforeItem: beforeIdentifier) - } - - public mutating func insertItems(_ identifiers: [ItemID], afterItem afterIdentifier: ItemID) { - - self.diffableSnapshot.insertItems(identifiers, afterItem: afterIdentifier) - } - - public mutating func deleteItems(_ identifiers: [ItemID]) { - - self.diffableSnapshot.deleteItems(identifiers) - } - - public mutating func deleteAllItems() { - - self.diffableSnapshot.deleteAllItems() - } - - public mutating func moveItem(_ identifier: ItemID, beforeItem toIdentifier: ItemID) { - - self.diffableSnapshot.moveItem(identifier, beforeItem: toIdentifier) - } - - public mutating func moveItem(_ identifier: ItemID, afterItem toIdentifier: ItemID) { - - self.diffableSnapshot.moveItem(identifier, afterItem: toIdentifier) - } - - public mutating func reloadItems(_ identifiers: [ItemID]) { - - self.diffableSnapshot.reloadItems(identifiers) - } - - public mutating func appendSections(_ identifiers: [SectionID]) { - - self.diffableSnapshot.appendSections(identifiers) - } - - public mutating func insertSections(_ identifiers: [SectionID], beforeSection toIdentifier: SectionID) { - - self.diffableSnapshot.insertSections(identifiers, beforeSection: toIdentifier) - } - - public mutating func insertSections(_ identifiers: [SectionID], afterSection toIdentifier: SectionID) { - - self.diffableSnapshot.insertSections(identifiers, afterSection: toIdentifier) - } - - public mutating func deleteSections(_ identifiers: [SectionID]) { - - self.diffableSnapshot.deleteSections(identifiers) - } - - public mutating func moveSection(_ identifier: SectionID, beforeSection toIdentifier: SectionID) { - - self.diffableSnapshot.moveSection(identifier, beforeSection: toIdentifier) - } - - public mutating func moveSection(_ identifier: SectionID, afterSection toIdentifier: SectionID) { - - self.diffableSnapshot.moveSection(identifier, afterSection: toIdentifier) - } - - public mutating func reloadSections(_ identifiers: [SectionID]) { - - self.diffableSnapshot.reloadSections(identifiers) - } + /** + Returns an array of `ObjectPublisher`s for the items at the specified indices + - parameter indices: the positions of items. Specifying an invalid value will raise an exception. + - returns: an array of `ObjectPublisher`s for the items at the specified indices + */ public func items(atIndices indices: S) -> [ObjectPublisher] where S.Element == Index { let context = self.context! @@ -341,7 +344,13 @@ public struct ListSnapshot: RandomAccessCollection, Hashable { } } - public subscript(section sectionID: SectionID) -> [ObjectPublisher] { + /** + Returns an array of `ObjectPublisher`s for the items in the specified `SectionID` + + - parameter sectionID: the `SectionID`. Specifying an invalid value will raise an exception. + - returns: an array of `ObjectPublisher`s for the items in the specified `SectionID` + */ + public func items(inSectionWithID sectionID: SectionID) -> [ObjectPublisher] { let context = self.context! let itemIDs = self.diffableSnapshot.itemIdentifiers(inSection: sectionID) @@ -351,7 +360,14 @@ public struct ListSnapshot: RandomAccessCollection, Hashable { } } - public subscript(section sectionID: SectionID, itemIndices itemIndices: S) -> [ObjectPublisher] where S.Element == Int { + /** + Returns an array of `ObjectPublisher`s for the items in the specified `SectionID` and indices + + - parameter sectionID: the `SectionID`. Specifying an invalid value will raise an exception. + - parameter itemIndices: the positions of items within the section. Specifying an invalid value will raise an exception. + - returns: an array of `ObjectPublisher`s for the items in the specified `SectionID` and indices + */ + public func items(inSectionWithID sectionID: SectionID, atIndices itemIndices: S) -> [ObjectPublisher] where S.Element == Int { let context = self.context! let itemIDs = self.diffableSnapshot.itemIdentifiers(inSection: sectionID) @@ -362,6 +378,135 @@ public struct ListSnapshot: RandomAccessCollection, Hashable { } } + /** + Returns a lazy sequence of `ObjectPublisher`s for the items at the specified indices + + - parameter indices: the positions of items. Specifying an invalid value will raise an exception. + - returns: a lazy sequence of `ObjectPublisher`s for the items at the specified indices + */ + public func lazy(atIndices indices: S) -> LazyMapSequence> where S.Element == Index { + + let context = self.context! + let itemIDs = self.diffableSnapshot.itemIdentifiers + return indices.lazy.map { position in + + let itemID = itemIDs[position] + return ObjectPublisher(objectID: itemID, context: context) + } + } + + /** + Returns a lazy sequence of `ObjectPublisher`s for the items in the specified `SectionID` + + - parameter sectionID: the `SectionID`. Specifying an invalid value will raise an exception. + - returns: a lazy sequence of `ObjectPublisher`s for the items in the specified `SectionID` + */ + public func lazy(inSectionWithID sectionID: SectionID) -> LazyMapSequence<[NSManagedObjectID], ObjectPublisher> { + + let context = self.context! + let itemIDs = self.diffableSnapshot.itemIdentifiers(inSection: sectionID) + return itemIDs.lazy.map { + + return ObjectPublisher(objectID: $0, context: context) + } + } + + /** + Returns a lazy sequence of `ObjectPublisher`s for the items in the specified `SectionID` and indices + + - parameter sectionID: the `SectionID`. Specifying an invalid value will raise an exception. + - parameter itemIndices: the positions of items within the section. Specifying an invalid value will raise an exception. + - returns: a lazy sequence of `ObjectPublisher`s for the items in the specified `SectionID` and indices + */ + public func lazy(inSectionWithID sectionID: SectionID, atIndices itemIndices: S) -> LazyMapSequence> where S.Element == Int { + + let context = self.context! + let itemIDs = self.diffableSnapshot.itemIdentifiers(inSection: sectionID) + return itemIndices.lazy.map { position in + + let itemID = itemIDs[position] + return ObjectPublisher(objectID: itemID, context: context) + } + } + + + // MARK: Public (Mutators) + + public mutating func appendItems(withIDs itemIDs: [ItemID], toSectionWithID sectionID: SectionID? = nil) { + + self.diffableSnapshot.appendItems(itemIDs, toSection: sectionID) + } + + public mutating func insertItems(withIDs itemIDs: [ItemID], beforeItemID: ItemID) { + + self.diffableSnapshot.insertItems(itemIDs, beforeItem: beforeItemID) + } + + public mutating func insertItems(withIDs itemIDs: [ItemID], afterItemID: ItemID) { + + self.diffableSnapshot.insertItems(itemIDs, afterItem: afterItemID) + } + + public mutating func deleteItems(withIDs itemIDs: [ItemID]) { + + self.diffableSnapshot.deleteItems(itemIDs) + } + + public mutating func deleteAllItems() { + + self.diffableSnapshot.deleteAllItems() + } + + public mutating func moveItem(withID itemID: ItemID, beforeItemID: ItemID) { + + self.diffableSnapshot.moveItem(itemID, beforeItem: beforeItemID) + } + + public mutating func moveItem(withID itemID: ItemID, afterItemID: ItemID) { + + self.diffableSnapshot.moveItem(itemID, afterItem: afterItemID) + } + + public mutating func reloadItems(withIDs itemIDs: [ItemID]) { + + self.diffableSnapshot.reloadItems(itemIDs) + } + + public mutating func appendSections(withIDs sectionIDs: [SectionID]) { + + self.diffableSnapshot.appendSections(sectionIDs) + } + + public mutating func insertSections(withIDs sectionIDs: [SectionID], beforeSectionID: SectionID) { + + self.diffableSnapshot.insertSections(sectionIDs, beforeSection: beforeSectionID) + } + + public mutating func insertSections(withIDs sectionIDs: [SectionID], afterSectionID: SectionID) { + + self.diffableSnapshot.insertSections(sectionIDs, afterSection: afterSectionID) + } + + public mutating func deleteSections(withIDs sectionIDs: [SectionID]) { + + self.diffableSnapshot.deleteSections(sectionIDs) + } + + public mutating func moveSection(withID sectionID: SectionID, beforeSectionID: SectionID) { + + self.diffableSnapshot.moveSection(sectionID, beforeSection: beforeSectionID) + } + + public mutating func moveSection(withID sectionID: SectionID, afterSectionID: SectionID) { + + self.diffableSnapshot.moveSection(sectionID, afterSection: afterSectionID) + } + + public mutating func reloadSections(withIDs sectionIDs: [SectionID]) { + + self.diffableSnapshot.reloadSections(sectionIDs) + } + // MARK: RandomAccessCollection diff --git a/Sources/SynchronousDataTransaction.swift b/Sources/SynchronousDataTransaction.swift index f456229..4f84a4f 100644 --- a/Sources/SynchronousDataTransaction.swift +++ b/Sources/SynchronousDataTransaction.swift @@ -98,6 +98,21 @@ public final class SynchronousDataTransaction: BaseDataTransaction { return super.edit(into, objectID) } + /** + Deletes the objects with the specified `NSManagedObjectID`s. + + - parameter objectIDs: the `NSManagedObjectID`s of the objects to delete + */ + public override func delete(objectIDs: S) where S.Iterator.Element: NSManagedObjectID { + + Internals.assert( + !self.isCommitted, + "Attempted to delete an entities from an already committed \(Internals.typeName(self))." + ) + + super.delete(objectIDs: objectIDs) + } + /** Deletes the specified `NSManagedObject`s or `CoreStoreObject`s represented by series of `ObjectRepresentation`s.