Replaces the specified subrange of elements with the given collection.
SDK
- Xcode 7.1+
Framework
- Swift Standard Library
Declaration
Parameters
subrange
The subrange of the collection to replace. The bounds of the range must be valid indices of the collection.
newElements
The new elements to add to the collection.
Discussion
This method has the effect of removing the specified range of elements from the collection and inserting the new elements at the same location. The number of new elements need not match the number of elements being removed.
In this example, three elements in the middle of an array of integers are replaced by the five elements of a Repeated<Int>
instance.
If you pass a zero-length range as the subrange
parameter, this method inserts the elements of new
at subrange
. Calling the insert(contents
method instead is preferred.
Likewise, if you pass a zero-length collection as the new
parameter, this method removes the elements in the given subrange without replacement. Calling the remove
method instead is preferred.
Calling this method may invalidate any existing indices for use with this collection.
Complexity: O(n + m), where n is length of this collection and m is the length of new
. If the call to this method simply appends the contents of new
to the collection, this method is equivalent to append(contents
.
Note
This documentation comment was inherited from Range
.