diff --git a/Sources/Internals.DiffableDataSourceSnapshot.swift b/Sources/Internals.DiffableDataSourceSnapshot.swift index cfa7f05..e4388c6 100644 --- a/Sources/Internals.DiffableDataSourceSnapshot.swift +++ b/Sources/Internals.DiffableDataSourceSnapshot.swift @@ -126,22 +126,22 @@ extension Internals { return self.structure.allSectionIDs.firstIndex(of: identifier) } - mutating func appendItems(_ identifiers: [NSManagedObjectID], toSection sectionIdentifier: String?) { + mutating func appendItems(_ identifiers: C, toSection sectionIdentifier: String?) where C.Element == NSManagedObjectID { self.structure.append(itemIDs: identifiers, to: sectionIdentifier) } - mutating func insertItems(_ identifiers: [NSManagedObjectID], beforeItem beforeIdentifier: NSManagedObjectID) { + mutating func insertItems(_ identifiers: C, beforeItem beforeIdentifier: NSManagedObjectID) where C.Element == NSManagedObjectID { self.structure.insert(itemIDs: identifiers, before: beforeIdentifier) } - mutating func insertItems(_ identifiers: [NSManagedObjectID], afterItem afterIdentifier: NSManagedObjectID) { + mutating func insertItems(_ identifiers: C, afterItem afterIdentifier: NSManagedObjectID) where C.Element == NSManagedObjectID { self.structure.insert(itemIDs: identifiers, after: afterIdentifier) } - mutating func deleteItems(_ identifiers: [NSManagedObjectID]) { + mutating func deleteItems(_ identifiers: S) where S.Element == NSManagedObjectID { self.structure.remove(itemIDs: identifiers) } @@ -161,27 +161,27 @@ extension Internals { self.structure.move(itemID: identifier, after: toIdentifier) } - mutating func reloadItems(_ identifiers: [NSManagedObjectID]) { + mutating func reloadItems(_ identifiers: S) where S.Element == NSManagedObjectID { self.structure.update(itemIDs: identifiers) } - mutating func appendSections(_ identifiers: [String]) { + mutating func appendSections(_ identifiers: C) where C.Element == String { self.structure.append(sectionIDs: identifiers) } - mutating func insertSections(_ identifiers: [String], beforeSection toIdentifier: String) { + mutating func insertSections(_ identifiers: C, beforeSection toIdentifier: String) where C.Element == String { self.structure.insert(sectionIDs: identifiers, before: toIdentifier) } - mutating func insertSections(_ identifiers: [String], afterSection toIdentifier: String) { + mutating func insertSections(_ identifiers: C, afterSection toIdentifier: String) where C.Element == String { self.structure.insert(sectionIDs: identifiers, after: toIdentifier) } - mutating func deleteSections(_ identifiers: [String]) { + mutating func deleteSections(_ identifiers: S) where S.Element == String { self.structure.remove(sectionIDs: identifiers) } @@ -196,7 +196,7 @@ extension Internals { self.structure.move(sectionID: identifier, after: toIdentifier) } - mutating func reloadSections(_ identifiers: [String]) { + mutating func reloadSections(_ identifiers: S) where S.Element == String { self.structure.update(sectionIDs: identifiers) } @@ -351,7 +351,7 @@ extension Internals { return self.itemPositionMap(itemID)?.section.differenceIdentifier } - mutating func append(itemIDs: [NSManagedObjectID], to sectionID: String?) { + mutating func append(itemIDs: C, to sectionID: String?) where C.Element == NSManagedObjectID { let index: Array
.Index if let sectionID = sectionID { @@ -375,7 +375,7 @@ extension Internals { self.sections[index].elements.append(contentsOf: items) } - mutating func insert(itemIDs: [NSManagedObjectID], before beforeItemID: NSManagedObjectID) { + mutating func insert(itemIDs: C, before beforeItemID: NSManagedObjectID) where C.Element == NSManagedObjectID { guard let itemPosition = self.itemPositionMap(beforeItemID) else { @@ -386,7 +386,7 @@ extension Internals { .insert(contentsOf: items, at: itemPosition.itemRelativeIndex) } - mutating func insert(itemIDs: [NSManagedObjectID], after afterItemID: NSManagedObjectID) { + mutating func insert(itemIDs: C, after afterItemID: NSManagedObjectID) where C.Element == NSManagedObjectID { guard let itemPosition = self.itemPositionMap(afterItemID) else { @@ -399,7 +399,7 @@ extension Internals { .insert(contentsOf: items, at: itemIndex) } - mutating func remove(itemIDs: C) where C.Element == NSManagedObjectID { + mutating func remove(itemIDs: S) where S.Element == NSManagedObjectID { let itemPositionMap = self.itemPositionMap() var removeIndexSetMap: [Int: IndexSet] = [:] @@ -482,13 +482,13 @@ extension Internals { self.reloadedItems.formUnion(newItemIDs) } - mutating func append(sectionIDs: [String]) { + mutating func append(sectionIDs: C) where C.Element == String { let newSections = sectionIDs.lazy.map({ Section(differenceIdentifier: $0) }) self.sections.append(contentsOf: newSections) } - mutating func insert(sectionIDs: [String], before beforeSectionID: String) { + mutating func insert(sectionIDs: C, before beforeSectionID: String) where C.Element == String { guard let sectionIndex = self.sectionIndex(of: beforeSectionID) else { @@ -498,7 +498,7 @@ extension Internals { self.sections.insert(contentsOf: newSections, at: sectionIndex) } - mutating func insert(sectionIDs: [String], after afterSectionID: String) { + mutating func insert(sectionIDs: C, after afterSectionID: String) where C.Element == String { guard let beforeIndex = self.sectionIndex(of: afterSectionID) else { @@ -509,7 +509,7 @@ extension Internals { self.sections.insert(contentsOf: newSections, at: sectionIndex) } - mutating func remove(sectionIDs: [String]) { + mutating func remove(sectionIDs: S) where S.Element == String { for sectionID in sectionIDs { diff --git a/Sources/ListSnapshot.swift b/Sources/ListSnapshot.swift index b508fa1..9ed1f92 100644 --- a/Sources/ListSnapshot.swift +++ b/Sources/ListSnapshot.swift @@ -446,7 +446,7 @@ public struct ListSnapshot: RandomAccessCollection, Hashable { - parameter itemIDs: the object identifiers for the objects to append - parameter sectionID: the section to append the items to */ - public mutating func appendItems(withIDs itemIDs: [ItemID], toSectionWithID sectionID: SectionID? = nil) { + public mutating func appendItems(withIDs itemIDs: C, toSectionWithID sectionID: SectionID? = nil) where C.Element == ItemID { self.diffableSnapshot.appendItems(itemIDs, toSection: sectionID) } @@ -457,7 +457,7 @@ public struct ListSnapshot: RandomAccessCollection, Hashable { - parameter itemIDs: the object identifiers for the objects to insert - parameter beforeItemID: an existing identifier to insert items before of. Specifying an invalid value will raise an exception. */ - public mutating func insertItems(withIDs itemIDs: [ItemID], beforeItemID: ItemID) { + public mutating func insertItems(withIDs itemIDs: C, beforeItemID: ItemID) where C.Element == ItemID { self.diffableSnapshot.insertItems(itemIDs, beforeItem: beforeItemID) } @@ -468,7 +468,7 @@ public struct ListSnapshot: RandomAccessCollection, Hashable { - parameter itemIDs: the object identifiers for the objects to insert - parameter beforeItemID: an existing identifier to insert items after of. Specifying an invalid value will raise an exception. */ - public mutating func insertItems(withIDs itemIDs: [ItemID], afterItemID: ItemID) { + public mutating func insertItems(withIDs itemIDs: C, afterItemID: ItemID) where C.Element == ItemID { self.diffableSnapshot.insertItems(itemIDs, afterItem: afterItemID) } @@ -478,7 +478,7 @@ public struct ListSnapshot: RandomAccessCollection, Hashable { - parameter itemIDs: the object identifiers for the objects to delete */ - public mutating func deleteItems(withIDs itemIDs: [ItemID]) { + public mutating func deleteItems(withIDs itemIDs: S) where S.Element == ItemID { self.diffableSnapshot.deleteItems(itemIDs) } @@ -518,7 +518,7 @@ public struct ListSnapshot: RandomAccessCollection, Hashable { - parameter itemIDs: the object identifiers to reload */ - public mutating func reloadItems(withIDs itemIDs: [ItemID]) { + public mutating func reloadItems(withIDs itemIDs: S) where S.Element == ItemID { self.diffableSnapshot.reloadItems(itemIDs) } @@ -528,7 +528,7 @@ public struct ListSnapshot: RandomAccessCollection, Hashable { - parameter sectionIDs: the sections to append */ - public mutating func appendSections(withIDs sectionIDs: [SectionID]) { + public mutating func appendSections(withIDs sectionIDs: C) where C.Element == SectionID { self.diffableSnapshot.appendSections(sectionIDs) } @@ -539,7 +539,7 @@ public struct ListSnapshot: RandomAccessCollection, Hashable { - parameter sectionIDs: the section identifiers for the sections to insert - parameter beforeSectionID: an existing identifier to insert items before of. Specifying an invalid value will raise an exception. */ - public mutating func insertSections(withIDs sectionIDs: [SectionID], beforeSectionID: SectionID) { + public mutating func insertSections(withIDs sectionIDs: C, beforeSectionID: SectionID) where C.Element == SectionID { self.diffableSnapshot.insertSections(sectionIDs, beforeSection: beforeSectionID) } @@ -550,7 +550,7 @@ public struct ListSnapshot: RandomAccessCollection, Hashable { - parameter sectionIDs: the section identifiers for the sections to insert - parameter beforeSectionID: an existing identifier to insert items after of. Specifying an invalid value will raise an exception. */ - public mutating func insertSections(withIDs sectionIDs: [SectionID], afterSectionID: SectionID) { + public mutating func insertSections(withIDs sectionIDs: C, afterSectionID: SectionID) where C.Element == SectionID { self.diffableSnapshot.insertSections(sectionIDs, afterSection: afterSectionID) } @@ -560,7 +560,7 @@ public struct ListSnapshot: RandomAccessCollection, Hashable { - parameter sectionIDs: the section identifiers for the sections to delete */ - public mutating func deleteSections(withIDs sectionIDs: [SectionID]) { + public mutating func deleteSections(withIDs sectionIDs: S) where S.Element == SectionID { self.diffableSnapshot.deleteSections(sectionIDs) } @@ -592,7 +592,7 @@ public struct ListSnapshot: RandomAccessCollection, Hashable { - parameter sectionIDs: the section identifiers to reload */ - public mutating func reloadSections(withIDs sectionIDs: [SectionID]) { + public mutating func reloadSections(withIDs sectionIDs: S) where S.Element == SectionID { self.diffableSnapshot.reloadSections(sectionIDs) }