subarray(with:)
Returns a new array containing the receiving array’s elements that fall within the limits specified by a given range.
Declaration
func subarray(with range: NSRange) -> [Any]Parameters
- range:
A range within the receiving array’s range of elements.
Return Value
A new array containing the receiving array’s elements that fall within the limits specified by range.
Discussion
If range isn’t within the receiving array’s range of elements, an NSRangeException is raised.
For example, the following code example creates an array containing the elements found in the first half of wholeArray (assuming wholeArray exists).
NSArray *halfArray;
NSRange theRange;
theRange.location = 0;
theRange.length = [wholeArray count] / 2;
halfArray = [wholeArray subarrayWithRange:theRange];