MutableArray
public class MutableArray<Element> : MutableCollection, CustomStringConvertible where Element : Equatable
A modifiable array of elements.
-
A string representing the array
Declaration
Swift
public var description: String { get }
-
Number of items in array
Declaration
Swift
public var count: Int { get }
-
Sequence method to create an iterator for the MutableSet.
Declaration
Swift
public func makeIterator() -> Array<Element>.Iterator
-
Declaration
Swift
public func index(after i: Int) -> Int
Parameters
i
A valid index of the collection. i must be less than endIndex.
-
The position of the first element in a nonempty array.
Declaration
Swift
public var startIndex: MutableArray<Element>.Index { get }
-
The array’s “past the end” position—that is, the position one greater than the last valid subscript argument.
Declaration
Swift
public var endIndex: MutableArray<Element>.Index { get }
-
Accesses the element at the specified position.
Modifies: The setter modifies self.
Effects: The setter updates the value at index.
Declaration
Swift
public subscript(index: Int) -> Element { get set }
Parameters
index
The position of the element to access. index must be greater than or equal to startIndex and less than endIndex.
-
Adds a new element at the end of the array.
Modifies: self
Effects: adds elem to the end.
Declaration
Swift
public func append(_ elem: Element)
Parameters
elem
The element to append to the array.
-
Inserts a new element into the collection at the specified position.
Modifies: self
Effects: inserts elem at the given index.
Declaration
Swift
public func insert(_ elem: Element, at index: Int)
Parameters
elem
The new element to insert into the collection.
index
The position at which to insert the new element. index must be a valid index into the collection.
-
Removes and returns the element at the specified position.
Modifies: self
Effects: removes the element at index.
Declaration
Swift
public func remove(at index: Int) -> Element
Parameters
index
The position of the element to remove. index must be a valid index of the array.
Return Value
The element at the specified index.
-
Removes and returns last element in the array.
Modifies: self
Effects: removes the last element in the array, if exists.
Declaration
Swift
public func removeLast() -> Element?
Return Value
The element removed, or nil if array was empty.
-
Returns a Boolean value that indicates whether the given element exists in the set.
Declaration
Swift
public func contains(_ elem: Element) -> Bool
Parameters
elem
An element to look for in the set.
Return Value
true if member exists in the set; otherwise, false.