11import Foundation
22import DifferenceKit
33
4- final class SnapshotStructure < SectionID: Hashable , ItemID: Hashable > {
4+ struct SnapshotStructure < SectionID: Hashable , ItemID: Hashable > {
55 struct Item : Differentiable , Equatable {
66 var differenceIdentifier : ItemID
77 var isReloaded : Bool
@@ -68,7 +68,7 @@ final class SnapshotStructure<SectionID: Hashable, ItemID: Hashable> {
6868 return itemPositionMap ( ) [ itemID] ? . section. differenceIdentifier
6969 }
7070
71- func append( itemIDs: [ ItemID ] , to sectionID: SectionID ? = nil , file: StaticString = #file, line: UInt = #line) {
71+ mutating func append( itemIDs: [ ItemID ] , to sectionID: SectionID ? = nil , file: StaticString = #file, line: UInt = #line) {
7272 let index : Array < Section > . Index
7373
7474 if let sectionID = sectionID {
@@ -90,7 +90,7 @@ final class SnapshotStructure<SectionID: Hashable, ItemID: Hashable> {
9090 sections [ index] . elements. append ( contentsOf: items)
9191 }
9292
93- func insert( itemIDs: [ ItemID ] , before beforeItemID: ItemID , file: StaticString = #file, line: UInt = #line) {
93+ mutating func insert( itemIDs: [ ItemID ] , before beforeItemID: ItemID , file: StaticString = #file, line: UInt = #line) {
9494 guard let itemPosition = itemPositionMap ( ) [ beforeItemID] else {
9595 specifiedItemIsNotFound ( beforeItemID, file: file, line: line)
9696 }
@@ -99,7 +99,7 @@ final class SnapshotStructure<SectionID: Hashable, ItemID: Hashable> {
9999 sections [ itemPosition. sectionIndex] . elements. insert ( contentsOf: items, at: itemPosition. itemRelativeIndex)
100100 }
101101
102- func insert( itemIDs: [ ItemID ] , after afterItemID: ItemID , file: StaticString = #file, line: UInt = #line) {
102+ mutating func insert( itemIDs: [ ItemID ] , after afterItemID: ItemID , file: StaticString = #file, line: UInt = #line) {
103103 guard let itemPosition = itemPositionMap ( ) [ afterItemID] else {
104104 specifiedItemIsNotFound ( afterItemID, file: file, line: line)
105105 }
@@ -109,7 +109,7 @@ final class SnapshotStructure<SectionID: Hashable, ItemID: Hashable> {
109109 sections [ itemPosition. sectionIndex] . elements. insert ( contentsOf: items, at: itemIndex)
110110 }
111111
112- func remove( itemIDs: [ ItemID ] ) {
112+ mutating func remove( itemIDs: [ ItemID ] ) {
113113 let itemPositionMap = self . itemPositionMap ( )
114114 var removeIndexSetMap = [ Int: IndexSet] ( )
115115
@@ -128,13 +128,13 @@ final class SnapshotStructure<SectionID: Hashable, ItemID: Hashable> {
128128 }
129129 }
130130
131- func removeAllItems( ) {
131+ mutating func removeAllItems( ) {
132132 for sectionIndex in sections. indices {
133133 sections [ sectionIndex] . elements. removeAll ( )
134134 }
135135 }
136136
137- func move( itemID: ItemID , before beforeItemID: ItemID , file: StaticString = #file, line: UInt = #line) {
137+ mutating func move( itemID: ItemID , before beforeItemID: ItemID , file: StaticString = #file, line: UInt = #line) {
138138 guard let removed = remove ( itemID: itemID) else {
139139 specifiedItemIsNotFound ( itemID, file: file, line: line)
140140 }
@@ -146,7 +146,7 @@ final class SnapshotStructure<SectionID: Hashable, ItemID: Hashable> {
146146 sections [ itemPosition. sectionIndex] . elements. insert ( removed, at: itemPosition. itemRelativeIndex)
147147 }
148148
149- func move( itemID: ItemID , after afterItemID: ItemID , file: StaticString = #file, line: UInt = #line) {
149+ mutating func move( itemID: ItemID , after afterItemID: ItemID , file: StaticString = #file, line: UInt = #line) {
150150 guard let removed = remove ( itemID: itemID) else {
151151 specifiedItemIsNotFound ( itemID, file: file, line: line)
152152 }
@@ -159,7 +159,7 @@ final class SnapshotStructure<SectionID: Hashable, ItemID: Hashable> {
159159 sections [ itemPosition. sectionIndex] . elements. insert ( removed, at: itemIndex)
160160 }
161161
162- func update( itemIDs: [ ItemID ] , file: StaticString = #file, line: UInt = #line) {
162+ mutating func update( itemIDs: [ ItemID ] , file: StaticString = #file, line: UInt = #line) {
163163 let itemPositionMap = self . itemPositionMap ( )
164164
165165 for itemID in itemIDs {
@@ -171,12 +171,12 @@ final class SnapshotStructure<SectionID: Hashable, ItemID: Hashable> {
171171 }
172172 }
173173
174- func append( sectionIDs: [ SectionID ] ) {
174+ mutating func append( sectionIDs: [ SectionID ] ) {
175175 let newSections = sectionIDs. lazy. map ( Section . init)
176176 sections. append ( contentsOf: newSections)
177177 }
178178
179- func insert( sectionIDs: [ SectionID ] , before beforeSectionID: SectionID , file: StaticString = #file, line: UInt = #line) {
179+ mutating func insert( sectionIDs: [ SectionID ] , before beforeSectionID: SectionID , file: StaticString = #file, line: UInt = #line) {
180180 guard let sectionIndex = sectionIndex ( of: beforeSectionID) else {
181181 specifiedSectionIsNotFound ( beforeSectionID, file: file, line: line)
182182 }
@@ -185,7 +185,7 @@ final class SnapshotStructure<SectionID: Hashable, ItemID: Hashable> {
185185 sections. insert ( contentsOf: newSections, at: sectionIndex)
186186 }
187187
188- func insert( sectionIDs: [ SectionID ] , after afterSectionID: SectionID , file: StaticString = #file, line: UInt = #line) {
188+ mutating func insert( sectionIDs: [ SectionID ] , after afterSectionID: SectionID , file: StaticString = #file, line: UInt = #line) {
189189 guard let beforeIndex = sectionIndex ( of: afterSectionID) else {
190190 specifiedSectionIsNotFound ( afterSectionID, file: file, line: line)
191191 }
@@ -195,13 +195,13 @@ final class SnapshotStructure<SectionID: Hashable, ItemID: Hashable> {
195195 sections. insert ( contentsOf: newSections, at: sectionIndex)
196196 }
197197
198- func remove( sectionIDs: [ SectionID ] ) {
198+ mutating func remove( sectionIDs: [ SectionID ] ) {
199199 for sectionID in sectionIDs {
200200 remove ( sectionID: sectionID)
201201 }
202202 }
203203
204- func move( sectionID: SectionID , before beforeSectionID: SectionID , file: StaticString = #file, line: UInt = #line) {
204+ mutating func move( sectionID: SectionID , before beforeSectionID: SectionID , file: StaticString = #file, line: UInt = #line) {
205205 guard let removed = remove ( sectionID: sectionID) else {
206206 specifiedSectionIsNotFound ( sectionID, file: file, line: line)
207207 }
@@ -213,7 +213,7 @@ final class SnapshotStructure<SectionID: Hashable, ItemID: Hashable> {
213213 sections. insert ( removed, at: sectionIndex)
214214 }
215215
216- func move( sectionID: SectionID , after afterSectionID: SectionID , file: StaticString = #file, line: UInt = #line) {
216+ mutating func move( sectionID: SectionID , after afterSectionID: SectionID , file: StaticString = #file, line: UInt = #line) {
217217 guard let removed = remove ( sectionID: sectionID) else {
218218 specifiedSectionIsNotFound ( sectionID, file: file, line: line)
219219 }
@@ -226,7 +226,7 @@ final class SnapshotStructure<SectionID: Hashable, ItemID: Hashable> {
226226 sections. insert ( removed, at: sectionIndex)
227227 }
228228
229- func update( sectionIDs: [ SectionID ] ) {
229+ mutating func update( sectionIDs: [ SectionID ] ) {
230230 for sectionID in sectionIDs {
231231 guard let sectionIndex = sectionIndex ( of: sectionID) else {
232232 continue
@@ -250,7 +250,7 @@ private extension SnapshotStructure {
250250 }
251251
252252 @discardableResult
253- func remove( itemID: ItemID ) -> Item ? {
253+ mutating func remove( itemID: ItemID ) -> Item ? {
254254 guard let itemPosition = itemPositionMap ( ) [ itemID] else {
255255 return nil
256256 }
@@ -259,7 +259,7 @@ private extension SnapshotStructure {
259259 }
260260
261261 @discardableResult
262- func remove( sectionID: SectionID ) -> Section ? {
262+ mutating func remove( sectionID: SectionID ) -> Section ? {
263263 guard let sectionIndex = sectionIndex ( of: sectionID) else {
264264 return nil
265265 }
0 commit comments