ArrayOperation
public struct ArrayOperation : Equatable
A value that represents a mutable operation on an array.
An array is frequently used to represent the data displayed by a UITableViewController
or a UICollectionViewController
.
When the array is updated, the view displayed must be updated accordingly,
This type is designed to simplify this update, and even better to animate this update.
This type does not store the array itself.
Instances of this type are returned by the following methods:
Array.updateOperation(for:)
Array.updateOrInsert(_:areSame:areEqual:isBefore:)
and its overloadsArray.remove(_:areSame:)
and its overloadArray.removeFirst(where:)
Array.removeAllReturningOperation(where:)
Array.removeAllReturningOperation()
-
The operation that does nothing applied on an empty array.
Declaration
Swift
public static let nothing: ArrayOperation
-
Creates a new instance.
Declaration
Swift
public init(initialCount: Int, updatedIndices: [Int] = [], removedIndices: [Int] = [], insertedIndices: [Int] = [])
Parameters
initialCount
The initial number of elements in the array before the operation.
updatedIndices
The indices of the updated elements before the update.
removedIndices
The indices of the removed elements.
insertedIndices
The indices of the inserted elements after the update.
-
Returns an operation that represents the same operation on a reversed array.
This property is useful when the view displays the elements of the array starting from the last one.
Declaration
Swift
public var reversed: ArrayOperation { get }
-
Applies the operation to a table view.
Declaration
Swift
public func apply(to tableView: UITableView, section: Int = 0, animation: UITableView.RowAnimation = .automatic)
Parameters
tableView
The table view to update accordingly to this value.
section
The section of the table view to update.
animation
The animation effect to use.
-
Applies the operation to a table view controller.
Declaration
Swift
public func apply(to tableViewController: UITableViewController, section: Int = 0, animation: UITableView.RowAnimation = .automatic)
Parameters
tableViewController
The table view controller of the view to update accordingly to this value.
section
The section of the table view to update.
animation
The animation effect to use.
-
Applies the operation to a collection view.
Declaration
Swift
public func apply(to collectionView: UICollectionView, section: Int = 0)
Parameters
collectionView
The collection view to update accordingly to this value.
section
The section of the collection view to update.
animation
The animation effect to use.
-
Applies the operation to a collection view controller.
Declaration
Swift
public func apply(to collectionViewController: UICollectionViewController, section: Int = 0)
Parameters
tableViewController
The collection view controller of the view to update accordingly to this value.
section
The section of the collection view to update.
animation
The animation effect to use.