windows(ofCount:)

Returns a collection of all the overlapping slices of a given size.

Windows.swift:42
func windows(ofCount count: Int) -> WindowsOfCountCollection<Self>

Parameters

count

The number of elements in each window subsequence.

Returns

A collection of subsequences of this collection, each with length count. If this collection is shorter than count, the resulting collection is empty.

Use this method to iterate over overlapping subsequences of this collection. This example prints every five character substring of str:

let str = "Hello, world!"
for substring in str.windows(ofCount: 5) {
    print(substring)
}
// "Hello"
// "ello,"
// "llo, "
// "lo, W"
// ...
// "orld!"