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
isIncluded
A 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.
element
An element of this array.
Return Value
An array of the indices of the elements that
isIncluded
allowed.
-
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) -> ArrayOperation
Parameters
index
The 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]) -> ArrayOperation
Parameters
indices
The 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 -> ArrayOperation
Parameters
isIncluded
A predicate indicating whether the update of an element must be represented in the result.
element
An 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 theelement
is inserted in the array according to the ordering predicate. - The array already contains an element representing the same entity as
element
and 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
element
and 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 -> ArrayOperation
Parameters
element
The element to update or insert.
areSame
The identity predicate: a predicate indicating whether its two arguments represent the same entity.
isBefore
The ordering predicate: a predicate indicating whether its first argument should be ordered before its second argument.
areEqual
The 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 itsid
property. In this case theelement
is inserted in the array according to the ordering predicate. - The array already contains an element representing the same entity as
element
and 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
element
and 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 : Identifiable
Parameters
element
The element to update or insert.
isBefore
The ordering predicate: a predicate indicating whether its first argument should be ordered before its second argument.
areEqual
The 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 itsid
property. In this case theelement
is inserted in the array according to the<
operator of theID
type. - The array already contains an element representing the same entity as
element
and 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
element
and 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 : Comparable
Parameters
element
The element to update or insert.
areEqual
The 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 theelement
is inserted in the array according to the ordering predicate. - The array already contains an element representing the same entity as
element
and 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
element
and 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 : Equatable
Parameters
element
The element to update or insert.
areSame
The identity predicate: a predicate indicating whether its two arguments represent the same entity.
isBefore
The 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 itsid
property. In this case theelement
is inserted in the array according to the ordering predicate. - The array already contains an element representing the same entity as
element
and 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
element
and 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 : Identifiable
Parameters
element
The element to update or insert.
isBefore
The 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 itsid
property. In this case theelement
is inserted in the array according to the<
operator of theID
type. - The array already contains an element representing the same entity as
element
and 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
element
and 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 : Comparable
Parameters
element
The 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 -> ArrayOperation
Parameters
element
The element representing the entity to remove.
areSame
A 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
.id
property.Declaration
Swift
@discardableResult public mutating func removeFirst(_ element: Element) -> ArrayOperation where Element : Identifiable
Parameters
element
The 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 -> ArrayOperation
Parameters
shouldBeRemoved
A predicate indicating whether an element must be removed.
element
An 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 -> ArrayOperation
Parameters
shouldBeRemoved
A predicate indicating whether an element must be removed.
element
An element of this array.
Return Value
An operation representing the removals.
-
Removes all the elements of this array.
Declaration
Swift
public mutating func removeAllReturningOperation() -> ArrayOperation
Return Value
An operation representing the removals.