Array
extension Array
-
Gets the element at the specified index starting from the end.
Declaration
Swift
public subscript(reversed index: Index) -> Element { get } -
Returns an array containing, in order, the indices of the elements that satisfy a predicate.
Declaration
Swift
public func indices(where isIncluded: (_ element: Element) throws -> Bool) rethrows -> [Index]Parameters
isIncludedA function that takes an element of this array and returns a Boolean indicating whether the index of that element should be included in the returned array.
elementAn element of this array.
Return Value
An array of the indices of the elements that
isIncludedallowed.
-
Returns an operation representing the update of an element in this array.
This method does not actually insert any element in the array.
Declaration
Swift
public func updateOperation(for index: Int) -> ArrayOperationParameters
indexThe index of the element whose update must be represented.
Return Value
An operation representing the update.
-
Returns an operation representing the update of elements in this array.
This method does not actually insert any element in the array.
Declaration
Swift
public func updateOperation(for indices: [Int]) -> ArrayOperationParameters
indicesThe indices of the elements whose update must be represented in the result.
Return Value
An operation representing the updates.
-
Returns an operation representing the update of the elements satisfying a predicate.
This method does not actually insert any element in the array.
Declaration
Swift
public func updateOperation(for isIncluded: (_ element: Element) throws -> Bool) rethrows -> ArrayOperationParameters
isIncludedA predicate indicating whether the update of an element must be represented in the result.
elementAn element of this array.
Return Value
An operation representing the updates.
-
Updates or inserts an element representing an entity in this array.
Each element of the array represents an entity of the real world in a certain state. The array does not contain multiple elements representing the same entity. Elements are sorted according to an ordering predicate.
There is three cases concerning the
element:- The array does not contain an element representing the same entity as
element, accordingly to the identity predicate. In this case theelementis inserted in the array according to the ordering predicate. - The array already contains an element representing the same entity as
elementand these two elements are in the same state, accordingly to the equality predicate. That means that the entity has not changed. There is nothing to do. - The array already contains an element representing the same entity as
elementand these two elements are in different states. That means that the entity has changed. The old element (representing the entity in its old state) is removed from the array and the newelement(representing the entity in its new sate) is inserted in the array according to the ordering predicate.
The returned operation is designed to animate the update of the table view controller or the collection view controller representing the content of this array.
Declaration
Swift
@discardableResult public mutating func updateOrInsert(_ element: Element, areSame: (Element, Element) throws -> Bool, isBefore: (Element, Element) throws -> Bool, areEqual: (Element, Element) throws -> Bool) rethrows -> ArrayOperationParameters
elementThe element to update or insert.
areSameThe identity predicate: a predicate indicating whether its two arguments represent the same entity.
isBeforeThe ordering predicate: a predicate indicating whether its first argument should be ordered before its second argument.
areEqualThe equality predicate: a predicate indicating whether its two arguments represent the same entity in the same state.
Return Value
An operation representing the update or the insertion.
- The array does not contain an element representing the same entity as
-
Updates or inserts an element representing an entity in this array.
Each element of the array represents an entity of the real world in a certain state. The array does not contain multiple elements representing the same entity. Elements are sorted according to an ordering predicate.
There is three cases concerning the
element:- The array does not contain an element representing the same entity as
element, accordingly to itsidproperty. In this case theelementis inserted in the array according to the ordering predicate. - The array already contains an element representing the same entity as
elementand these two elements are in the same state, accordingly to the equality predicate. That means that the entity has not changed. There is nothing to do. - The array already contains an element representing the same entity as
elementand these two elements are in different states. That means that the entity has changed. The old element (representing the entity in its old state) is removed from the array and the newelement(representing the entity in its new sate) is inserted in the array according to the ordering predicate.
The returned operation is designed to animate the update of the table view controller or the collection view controller representing the content of this array.
Declaration
Swift
@discardableResult public mutating func updateOrInsert(_ element: Element, isBefore: (Element, Element) throws -> Bool, areEqual: (Element, Element) throws -> Bool) rethrows -> ArrayOperation where Element : IdentifiableParameters
elementThe element to update or insert.
isBeforeThe ordering predicate: a predicate indicating whether its first argument should be ordered before its second argument.
areEqualThe equality predicate: a predicate indicating whether its two arguments represent the same entity in the same state.
Return Value
An operation representing the update or the insertion.
- The array does not contain an element representing the same entity as
-
Updates or inserts an element representing an entity in this array.
Each element of the array represents an entity of the real world in a certain state. The array does not contain multiple elements representing the same entity. Elements are sorted according to an ordering predicate.
There is three cases concerning the
element:- The array does not contain an element representing the same entity as
element, accordingly to itsidproperty. In this case theelementis inserted in the array according to the<operator of theIDtype. - The array already contains an element representing the same entity as
elementand these two elements are in the same state, accordingly to the equality predicate. That means that the entity has not changed. There is nothing to do. - The array already contains an element representing the same entity as
elementand these two elements are in different states. That means that the entity has changed. The old element (representing the entity in its old state) is removed from the array and the newelement(representing the entity in its new sate) is inserted at the same place.
The returned operation is designed to animate the update of the table view controller or the collection view controller representing the content of this array.
Declaration
Swift
@discardableResult public mutating func updateOrInsert(_ element: Element, areEqual: (Element, Element) throws -> Bool) rethrows -> ArrayOperation where Element : Identifiable, Element.ID : ComparableParameters
elementThe element to update or insert.
areEqualThe equality predicate: a predicate indicating whether its two arguments represent the same entity in the same state.
Return Value
An operation representing the update or the insertion.
- The array does not contain an element representing the same entity as
-
Updates or inserts an element representing an entity in this array.
Each element of the array represents an entity of the real world in a certain state. The array does not contain multiple elements representing the same entity. Elements are sorted according to an ordering predicate.
There is three cases concerning the
element:- The array does not contain an element representing the same entity as
element, accordingly to the identity predicate. In this case theelementis inserted in the array according to the ordering predicate. - The array already contains an element representing the same entity as
elementand these two elements are in the same state, accordingly to the==operator. That means that the entity has not changed. There is nothing to do. - The array already contains an element representing the same entity as
elementand these two elements are in different states. That means that the entity has changed. The old element (representing the entity in its old state) is removed from the array and the newelement(representing the entity in its new sate) is inserted in the array according to the ordering predicate.
The returned operation is designed to animate the update of the table view controller or the collection view controller representing the content of this array.
Declaration
Swift
@discardableResult public mutating func updateOrInsert(_ element: Element, areSame: (Element, Element) throws -> Bool, isBefore: (Element, Element) throws -> Bool) rethrows -> ArrayOperation where Element : EquatableParameters
elementThe element to update or insert.
areSameThe identity predicate: a predicate indicating whether its two arguments represent the same entity.
isBeforeThe ordering predicate: a predicate indicating whether its first argument should be ordered before its second argument.
Return Value
An operation representing the update or the insertion.
- The array does not contain an element representing the same entity as
-
Updates or inserts an element representing an entity in this array.
Each element of the array represents an entity of the real world in a certain state. The array does not contain multiple elements representing the same entity. Elements are sorted according to an ordering predicate.
There is three cases concerning the
element:- The array does not contain an element representing the same entity as
element, accordingly to itsidproperty. In this case theelementis inserted in the array according to the ordering predicate. - The array already contains an element representing the same entity as
elementand these two elements are in the same state, accordingly to the==operator. That means that the entity has not changed. There is nothing to do. - The array already contains an element representing the same entity as
elementand these two elements are in different states. That means that the entity has changed. The old element (representing the entity in its old state) is removed from the array and the newelement(representing the entity in its new sate) is inserted in the array according to the ordering predicate.
The returned operation is designed to animate the update of the table view controller or the collection view controller representing the content of this array.
Declaration
Swift
@discardableResult public mutating func updateOrInsert(_ element: Element, isBefore: (Element, Element) throws -> Bool) rethrows -> ArrayOperation where Element : Equatable, Element : IdentifiableParameters
elementThe element to update or insert.
isBeforeThe ordering predicate: a predicate indicating whether its first argument should be ordered before its second argument.
Return Value
An operation representing the update or the insertion.
- The array does not contain an element representing the same entity as
-
Updates or inserts an element representing an entity in this array.
Each element of the array represents an entity of the real world in a certain state. The array does not contain multiple elements representing the same entity. Elements are sorted according to an ordering predicate.
There is three cases concerning the
element:- The array does not contain an element representing the same entity as
element, accordingly to itsidproperty. In this case theelementis inserted in the array according to the<operator of theIDtype. - The array already contains an element representing the same entity as
elementand these two elements are in the same state, accordingly to the==operator. That means that the entity has not changed. There is nothing to do. - The array already contains an element representing the same entity as
elementand these two elements are in different states. That means that the entity has changed. The old element (representing the entity in its old state) is removed from the array and the newelement(representing the entity in its new sate) is inserted at the same place.
The returned operation is designed to animate the update of the table view controller or the collection view controller representing the content of this array.
Declaration
Swift
@discardableResult public mutating func updateOrInsert(_ element: Element) -> ArrayOperation where Element : Equatable, Element : Identifiable, Element.ID : ComparableParameters
elementThe element to update or insert.
Return Value
An operation representing the update or the insertion.
- The array does not contain an element representing the same entity as
-
Removes the first occurrence of an entity from this array.
This method removes the first element of this array that represents the same entity as the given element, if there is one.
Declaration
Swift
@discardableResult public mutating func removeFirst(_ element: Element, areSame: (Element, Element) throws -> Bool) rethrows -> ArrayOperationParameters
elementThe element representing the entity to remove.
areSameA predicate indicating whether its two arguments represent the same entity.
Return Value
An operation representing the removal.
-
Removes the first occurrence of an entity from this array.
This method removes the first element of this array that represents the same entity as the given element, if there is one according to its
.idproperty.Declaration
Swift
@discardableResult public mutating func removeFirst(_ element: Element) -> ArrayOperation where Element : IdentifiableParameters
elementThe element representing the entity to remove.
Return Value
An operation representing the removal.
-
Removes the first element of this array matching a given predicate.
Declaration
Swift
@discardableResult public mutating func removeFirst(where shouldBeRemoved: (_ element: Element) throws -> Bool) rethrows -> ArrayOperationParameters
shouldBeRemovedA predicate indicating whether an element must be removed.
elementAn element of this array.
Return Value
An operation representing the removal.
-
Removes all the elements of this array matching a given predicate.
Declaration
Swift
public mutating func removeAllReturningOperation(where shouldBeRemoved: (_ element: Element) throws -> Bool) rethrows -> ArrayOperationParameters
shouldBeRemovedA predicate indicating whether an element must be removed.
elementAn element of this array.
Return Value
An operation representing the removals.
-
Removes all the elements of this array.
Declaration
Swift
public mutating func removeAllReturningOperation() -> ArrayOperationReturn Value
An operation representing the removals.