Collection
public extension Collection
-
Wraps the result from an
enumerated
call in anArray
.Useful for
ForEach
loops which should enumerate over elements of an array which are not conforming toIdentifiable
.Example of usage:
let myArray = [something, anotherThing] ForEach(myArray.enumeratedArray(), id: \.offset) { offset, element in ... }
Declaration
Swift
func enumeratedArray() -> [(offset: Int, element: Self.Element)]
-
Returns the element at the specified index if it is within bounds, otherwise nil.
Declaration
Swift
subscript(safe index: Index) -> Element? { get }