選取您的 Cookie 偏好設定

我們使用提供自身網站和服務所需的基本 Cookie 和類似工具。我們使用效能 Cookie 收集匿名統計資料,以便了解客戶如何使用我們的網站並進行改進。基本 Cookie 無法停用,但可以按一下「自訂」或「拒絕」以拒絕效能 Cookie。

如果您同意,AWS 與經核准的第三方也會使用 Cookie 提供實用的網站功能、記住您的偏好設定,並顯示相關內容,包括相關廣告。若要接受或拒絕所有非必要 Cookie,請按一下「接受」或「拒絕」。若要進行更詳細的選擇,請按一下「自訂」。

Use AWS SDK for Swift paginators - AWS SDK for Swift
此頁面尚未翻譯為您的語言。 請求翻譯

Use AWS SDK for Swift paginators

Many AWS operations return paginated results when the payload is too large to return in a single response. The AWS SDK for Swift provides specialized versions of the functions that do this. These special functions end with the word Paginated. All your code needs to do is process the results as they arrive.

Each paginator is a function that returns an object of type PaginatorSequence<input-type, output-type>. The PaginatorSequence<> is an AsyncSequence; AsyncSequence is a "lazy" sequence, so no AWS service requests are made until you start iterating over the pages. This also means that any errors that occur during the operation don't reach you until iteration begins.

Note

The examples in this section of the developer guide use Amazon S3. However, the concept is the same for any service that has one or more paginated APIs.

For example, the paginated version of the S3Client function listBuckets(input:), listBucketsPaginated(input:), returns an object of type PaginatorSequence<ListBucketsInput, ListBucketsOutput>:

let pages = client.listBucketsPaginated( input: ListBucketsInput(maxBuckets: PAGE_SIZE) )

In this example, the number of results in each page is specified by adding a maxBuckets property to the ListBucketsInput object. Each paginator uses an appropriate name for this property. As of the time listBucketsPaginated(input:) returns, no requests have been sent to the Amazon S3 service.

The PaginatorSequence<> is a sequence of pages which are asynchronously added to the sequence as the results are received. The type of each entry in the sequence is the Output struct corresponding to the function called. For example, if you call S3Client.listBucketsPaginated(input:), each entry in the sequence is a ListBucketsOutput object. Each entry's buckets can be found in the its ListBucketsOutput.buckets property, which is an array of objects of type S3ClientTypes.Bucket.

To begin sending requests and receiving results, asynchronously iterate over each page, then iterate over each page's items:

var pageNumber = 0 do { for try await page in pages { pageNumber += 1 guard let pageBuckets = page.buckets else { print("ERROR: No buckets returned in page \(pageNumber)") continue } print("\nPage \(pageNumber):") // Print this page's bucket names. for bucket in pageBuckets { print(" " + (bucket.name ?? "<unknown>")) } } } catch { print("ERROR: Unable to process bucket list pages.") }

The outer for loop uses await to process pages of results as they're delivered, asynchronously. Once a page is received, the inner loop iterates over the buckets found in each entry's buckets property. The full example is available on GitHub.

下一個主題:

Presign requests

上一個主題:

Event streaming
隱私權網站條款Cookie 偏好設定
© 2025, Amazon Web Services, Inc.或其附屬公司。保留所有權利。