Returns the longest possible subsequences of the collection, in order, that don’t contain elements satisfying the given predicate.
- iOS 7.0+
- macOS 10.9+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 3.0+
- Xcode 9.0+
- Core Audio
The maximum number of times to split the collection, or one less than the number of subsequences to return. If
maxsubsequences are returned, the last one is a suffix of the original collection containing the remaining elements.
Splits + 1
maxmust be greater than or equal to zero. The default value is
false, an empty subsequence is returned in the result for each pair of consecutive elements satisfying the
ispredicate and for each element at the start or end of the collection satisfying the
ispredicate. The default value is
A closure that takes an element as an argument and returns a Boolean value indicating whether the collection should be split at that element.
An array of subsequences, split from this collection’s elements.
The resulting array consists of at most
max subsequences. Elements that are used to split the sequence are not returned as part of any subsequence.
The following examples show the effects of the
omitting parameters when splitting a string using a closure that matches spaces. The first use of
split returns each word that was originally separated by one or more spaces.
The second example passes
1 for the
max parameter, so the original string is split just once, into two new strings.
The final example passes
false for the
omitting parameter, so the returned array contains empty strings where spaces were repeated.
Complexity: O(n), where n is the length of the collection.