Pagination
-
A collection that provides paginated results from a Spotify Web API request.
Paging collections are either offset-based or cursor-based depending on the type of paging object returned by the API. The
PagingCollection
protocol serves as a base for common collection requirements.Paging collections inherit from the
See moreRandomAccessCollection
protocol, adopting all the functionality and efficiency of a bidirectional, random-access collection such asArray
. In addition to the paging and API-specific requirements, types that conform to this protocol must also implement the requirements of the Collection and BidirectionalCollection protocols—and in order to meet the complexity guarantees of a random-access collection, either the index must conform to the Strideable protocol, or theindex(_:offsetBy:)
anddistance(from:to:)
methods must be implemented with O(1) efficiency.Declaration
Swift
public protocol PagingCollection : RandomAccessCollection
-
A collection that supports offset-based pagination.
Offset-based paging collections use an
See moreoffset
index to paginate items in a larger list of results. Offset-based pagination is the default mechanism for returning paginated results from the Spotify Web API.Declaration
Swift
public protocol OffsetPagingCollection : PagingCollection
-
A collection that supports cursor-based pagination.
The
See moreCursorPagingCollection
protocol is tightly linked with theCursorProtocol
andCursorPageable
protocols. As opposed to offset-based paging collections, cursor-based paging collections depend on a set ofcursors
to identify the first and last items in a given page, providing reference points from which to page through a larger list of results, typically sorted in chronological order. The type of cursor used to identify the items depends on the type of items returned in the page. Therefore, types that conform to this protocol must also conform its elements toCursorPageable
and provide an associated type that conforms to theCursorProtocol
, where its cursor type matches that of the collection’sElement
.Declaration
Swift
public protocol CursorPagingCollection : PagingCollection where Self.Element : CursorPageable
-
A type that contains a set of cursors used to identify items and traverse adjacent pages in a cursor-based paging collection.
The
See moreCursorProtocol
protocol is tightly linked with theCursorPageable
andCursorPagingCollection
protocols. Cursor-based paging collections depend on a set ofcursors
to identify the first and last items in a given page, providing reference points from which to page through a larger list of results, typically sorted in chronological order. The type of cursor used to identify the items depends on the type of items returned in the page. Therefore, types that conform to this protocol must provide an associated cursor type that can be used to uniquely identify themselves within a paging collection.Declaration
Swift
public protocol CursorProtocol
-
A type that can be returned in a cursor-based paging collection.
The
CursorPageable
protocol is tightly linked with theCursorProtocol
andCursorPagingCollection
protocols. Cursor-based paging collections depend on a set ofcursors
to identify the first and last items in a given page, providing reference points from which to page through a larger list of results, typically sorted in chronological order. The type of cursor used to identify the items depends on the type of items returned in the page. Therefore, types that conform to this protocol must provide an associated cursor type that can be used to uniquely identify themselves within a paging collection.The cursor type must also be decodable.
See moreDeclaration
Swift
public protocol CursorPageable
-
A generic collection that provides offset-based paginated results from a Spotify Web API request.
See also
The Web API Paging object.Declaration
Swift
public struct Page<Element> : OffsetPagingCollection, JSONDecodable where Element : Decodable
-
A generic collection that provides cursor-based paginated results from a Spotify Web API request.
See also
The Web API Cursor-Based Paging object.Declaration
Swift
public struct CursorPage<Element> : CursorPagingCollection, JSONDecodable where Element : CursorPageable, Element : Decodable
-
A structure representing the parameters for paginating the elements of a larger collection.
See moreDeclaration
Swift
public struct Pagination