---
source_url: https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/users/list
title: List all users
updated_at: 2026-06-16T12:48:55.249Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# List all users

`getUsers()` returns a paginated list of all users with their metadata.

:::note Requires App Context
Enable [App Context](https://youtu.be/9UEoSlngpYI) in the [Admin Portal](https://admin.pubnub.com/) to store user data.
:::

### Method signature

This method takes the following parameters:

```swift
chat.getUsers(
    filter: String? = nil,
    sort: [PubNub.ObjectSortField] = [],
    limit: Int?,
    page: PubNubHashedPage? = nil
) async throws -> (users: [UserImpl], page: PubNubHashedPage?)
```

#### Input

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| filter | String | Optional |  | Expression used to filter the results. Returns only these users whose properties satisfy the given expression are returned. The filtering language is [defined here](https://www.pubnub.com/docs/general/metadata/filtering). |
| sort | [PubNub.ObjectSortField] | Optional | `[]` | A collection to specify the sort order. Available options are `id`, `name`, and `updated`. Use `asc` or `desc` to specify the sorting direction, or specify `null` to take the default sorting direction (ascending). For example: `{name: "asc"}`. Unless specified otherwise, the items are sorted by the last updated date. Defaults to an empty list. |
| limit | Int? | Optional | `nil` | Number of objects to return in response. The default value used by the server is `100`. The maximum value is `100`. |
| page | PubNubHashedPage | Optional |  | Object used for pagination to define which previous or next result page you want to fetch. |

#### Output

| Parameter | Description |
| --- | --- |
| `[UserImpl]` | Object containing a set of users with pagination information (`next`, `prev`, `total`). |

### Sample code

:::tip Sample code
The code samples in Swift Chat SDK focus on asynchronous code execution.
You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.
:::

Fetch all existing user IDs.

```swift
// Assumes a "ChatImpl" reference named "chat"
Task {
  // Fetch the first set of users.
  // There's no need to pass the "page" parameter, as it's nil by default, indicating the first page
  let getUsersResult = try await chat.getUsers()
  debugPrint("Fetched channels: \(getUsersResult.users)")
  debugPrint("Next page: \(String(describing: getUsersResult.page))")
    
  // The example below shows how to read the next page from the previous response and pass it to a subsequent call.
  // You can recursively keep fetching using the page objects from previous responses until the returned array is empty
  if let nextPage = getUsersResult.page, !getUsersResult.users.isEmpty {
    let resultsFromNextPage = try await chat.getUsers(page: nextPage)
  }
}
```

### Other examples

#### Pagination

Get the total number of 25 users and then specify that you want to fetch the results from the next page using a page that was previously returned from the PubNub server.

```swift
// Assumes a "ChatImpl" reference named "chat" and the "page" reference of "PubNubHashedPage" type
Task {
  let getUsersResult = try await chat.getUsers(limit: 25, page: page)
  debugPrint("Fetched channels: \(getUsersResult.users)")
  debugPrint("Next page: \(String(describing: getUsersResult.page))")
    
  // The example below shows how to read the next page and pass it to a subsequent call.
  // You can recursively keep fetching using the page objects from previous responses until the returned array is empty
  if let nextPage = getUsersResult.page, !getUsersResult.users.isEmpty {
    let resultsFromNextPage = try await chat.getUsers(limit: 25, page: nextPage)
  }
}
```

#### Archived users

Get all archived users. This request will return all users removed with the `soft` option set to `true`, whose data is still stored in the App Context storage.

```swift
// Assumes a "ChatImpl" reference named "chat"
Task {
  // Fetch the first set of users.
  // There's no need to pass the "page" parameter, as it's nil by default, indicating the first page
  let getUsersResult = try await chat.getUsers(filter: "status == 'deleted'", limit: 25)
  debugPrint("Fetched channels: \(getUsersResult.users)")
  debugPrint("Next page: \(String(describing: getUsersResult.page))")
    
  // The example below shows how to read the next page and pass it to a subsequent call.
  // You can recursively keep fetching using the page objects from previous responses until the returned array is empty
  if let nextPage = getUsersResult.page, !getUsersResult.users.isEmpty {
    let resultsFromNextPage = try await chat.getUsers(filter: "status == 'deleted'", limit: 25, page: nextPage)
  }
}
```