---
source_url: https://www.pubnub.com/docs/sdks/swift/api-reference/objects
title: App Context API for Swift Native SDK
updated_at: 2026-06-04T11:13:09.419Z
sdk_name: PubNub Swift SDK
sdk_version: 10.1.6
---

> 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


# App Context API for Swift Native SDK

PubNub Swift SDK, use the latest version: 10.1.6

Install:

```bash
Add PubNub via Swift Package Manager or CocoaPods@10.1.6
```

This page describes App Context (formerly Objects v2). To upgrade from Objects v1, refer to the [migration guide](https://www.pubnub.com/docs/general/resources/migration-guides/objects-v2-migration).

App Context provides easy-to-use, serverless storage for user and channel data you need to build innovative, reliable, scalable applications. Use App Context to store metadata about your application users and channels, and their membership associations, without the need to stand up your own databases.

PubNub also triggers events when object data is set or removed from the database. Clients can receive these events in real-time and update their front-end application accordingly.

:::note UUID and User ID
`PubNubUUIDMetadataBase` is deprecated but will continue to work as a typealias for `PubNubUserMetadataBase`.
:::

## User

### Get metadata for all users

Returns a paginated list of user metadata objects, optionally including the custom data object for each.

:::warning Required keyset configuration
To get all channel and user metadata, you must uncheck the
Disallow Get All Channel Metadata
and
Disallow Get All User Metadata
checkboxes in the App Context section of your keyset configuration in the
[Admin Portal](https://admin.pubnub.com)
.
:::

#### Method(s)

To `Get All User Metadata` you can use the following method(s) in the Swift SDK:

```swift
func allUserMetadata(
    include: PubNub.UserIncludeFields = PubNub.UserIncludeFields(),
    filter: String? = nil,
    sort: [PubNub.ObjectSortField] = [],
    limit: Int? = 100,
    page: PubNubHashedPage? = Page(),
    custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
    completion: ((Result<(users: [PubNubUserMetadata], next: PubNubHashedPage?), Error>) -> Void)?
)
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| include | PubNub.UserIncludeFields | Optional | `PubNub.UserIncludeFields()` | Whether to include additional fields. |
| filter | String? | Optional | `nil` | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined [here](https://www.pubnub.com/docs/general/metadata/filtering) |
| sort | [PubNub.ObjectSortField] | Optional | `[]` | List of properties to sort response objects. The following properties are valid for sorting: `.id`, `.name`, `.type`, `.status`, and `.updated`. |
| page | PubNubHashedPage? | Optional | `PubNub.Page()` | The paging object used for pagination that allows for cursor-based pagination where the pages are navigated using a cursor, such as a `next` value. |
| limit | Int? | Optional | `100` | The number of objects to retrieve at a time. |
| custom | PubNub.RequestConfiguration | Optional | `PubNub.RequestConfiguration()` | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the [Request Configuration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration) section. |
| completion | ((Result<(users: | Optional | `nil` | The async `Result` of the method call. |

#### UserIncludeFields

`PubNub.UserIncludeFields` is a struct that defines which additional fields should be included in the response when fetching user metadata. It allows fine-grained control over what data is returned, helping optimize response payload size and network efficiency.

| Property | Description |
| --- | --- |
| `custom`Type: `Bool`Default: `true` | Whether to include the custom dictionary for the user metadata object |
| `type`Type: `Bool`Default: `true` | Whether to include the type field for the user metadata object |
| `status`Type: `Bool`Default: `true` | Whether to include the status field for the user metadata object |
| `totalCount`Type: `Bool`Default: `true` | Whether to include the total count of how many user objects are available |

#### Completion handler result

##### Success

A `Tuple` containing an `Array` of `PubNubUserMetadata`, and the next pagination `PubNubHashedPage` (if one exists).

```swift
public protocol PubNubUserMetadata {

  /// The unique identifier of the User
  var metadataId: String { get }

  /// The name of the User
  var name: String { get set }

  /// The classification of User
  var type: String? { get set }

  /// The current state of the User
  var status: String? { get set }

  /// The external identifier for the object
  var externalId: String? { get set }

  /// The profile URL for the object
  var profileURL: String? { get set }

  /// The email address of the object
  var email: String? { get set }

  /// The last updated timestamp for the object
  var updated: Date? { get set }

  /// The caching identifier for the object
  var eTag: String? { get set }

  /// All custom fields set on the object
  var custom: [String: JSONCodableScalar]? { get set }
}
```

```swift
public protocol PubNubHashedPage {

  /// The hash value representing the next set of data
  var start: String? { get }

  /// The hash value representing the previous set of data
  var end: String? { get }

  /// The total count of all objects withing range
  var totalCount: Int? { get }
}
```

##### Failure

An `Error` describing the failure.

#### Sample code

:::tip Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.
:::

```swift
import PubNubSDK

// Initializes a PubNub object with the configuration
let pubnub = PubNub(
  configuration: PubNubConfiguration(
    publishKey: "demo",
    subscribeKey: "demo",
    userId: "myUniqueUserId"
  )
)

// Retrieve all user metadata
pubnub.allUserMetadata { result in
  switch result {
  case let .success(response):
    print("The user metadata objects: \(response.users)")
    print("The next page used for pagination: \(String(describing: response.next))")
  case let .failure(error):
    print("Fetch All request failed with error: \(error.localizedDescription)")
  }
}
```

### Get user metadata

Returns metadata for the specified User, optionally including the custom data object for each.

#### Method(s)

To `Get User Metadata` you can use the following method(s) in the Swift SDK:

```swift
func fetchUserMetadata(
    _ metadataId: String?,
    include: PubNub.UserIncludeFields = PubNub.UserIncludeFields(),
    custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
    completion: ((Result<PubNubUserMetadata, Error>) -> Void)?
)
```

| Parameter | Description |
| --- | --- |
| `metadataId` *Type: StringDefault: n/a | Unique User Metadata identifier. If not supplied, then it will use the request configuration and then the default configuration. |
| `include`Type: [PubNub.UserIncludeFields](#userincludefields)Default: `PubNub.UserIncludeFields()` | Whether to include additional fields. |
| `custom`Type: [PubNub.RequestConfiguration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration)Default: `PubNub.RequestConfiguration()` | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the [Request Configuration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration) section. |
| `completion`Type: `((Result<PubNubUserMetadata, Error>) -> Void)?`Default: `nil` | The async `Result` of the method call. |

#### Completion handler result

##### Success

The `PubNubUserMetadata` object belonging to the identifier.

```swift
public protocol PubNubUserMetadata {

  /// The unique identifier of the User
  var metadataId: String { get }

  /// The name of the User
  var name: String { get set }

  /// The classification of User
  var type: String? { get set }

  /// The current state of the User
  var status: String? { get set }

  /// The external identifier for the object
  var externalId: String? { get set }

  /// The profile URL for the object
  var profileURL: String? { get set }

  /// The email address of the object
  var email: String? { get set }

  /// The last updated timestamp for the object
  var updated: Date? { get set }

  /// The caching identifier for the object
  var eTag: String? { get set }

  /// All custom fields set on the object
  var custom: [String: JSONCodableScalar]? { get set }
}
```

##### Failure

An `Error` describing the failure.

#### Sample code

```swift
// Retrieve user metadata for a specific identifier
pubnub.fetchUserMetadata("some-id") { result in
  switch result {
  case let .success(userMetadata):
    print("The metadata for `\(userMetadata.metadataId)`: \(userMetadata)")
  case let .failure(error):
    print("Fetch request failed with error: \(error.localizedDescription)")
  }
}
```

### Set user metadata

:::warning Unsupported partial updates of custom metadata
The value of the custom metadata parameter sent in this method always overwrites the value stored on PubNub servers. If you want to add new custom data to an existing one, you must:
1. Get the existing metadata and store it locally.
2. Append the new custom metadata to the existing one.
3. Set the entire updated custom object.
:::

Set metadata for a User in the database, optionally including the custom data object for each.

#### Method(s)

To `Set User Metadata` you can use the following method(s) in the Swift SDK:

```swift
func setUserMetadata(
    _ metadata: PubNubUserMetadata,
    ifMatchesEtag: String? = nil,
    include: PubNub.UserIncludeFields = PubNub.UserIncludeFields(),
    custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
    completion: ((Result<PubNubUserMetadata, Error>) -> Void)?
)
```

| Parameter | Description |
| --- | --- |
| `metadata` *Type: PubNubUserMetadataDefault: n/a | User Metadata to set. |
| `ifMatchesEtag`Type: StringDefault: n/a | The entity tag to be used to ensure updates only happen if the object hasn't been modified since it was read. Use the eTag you received from an applicable get metadata method to check against the server entity tag. If the eTags don't match, an HTTP 412 error is thrown. |
| `include`Type: [PubNub.UserIncludeFields](#userincludefields)Default: `PubNub.UserIncludeFields()` | Whether to include additional fields. |
| `custom`Type: [PubNub.RequestConfiguration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration)Default: `PubNub.RequestConfiguration()` | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the [Request Configuration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration) section. |
| `completion`Type: `((Result<PubNubUserMetadata, Error>) -> Void)?`Default: `nil` | The async `Result` of the method call. |

:::tip API limits
To learn about the maximum length of parameters used to set user metadata, refer to [REST API docs](https://www.pubnub.com/docs/sdks/rest-api/set-user-metadata).
:::

#### Completion handler result

##### Success

The `PubNubUserMetadata` object belonging to the identifier.

```swift
public protocol PubNubUserMetadata {

  /// The unique identifier of the User
  var metadataId: String { get }

  /// The name of the User
  var name: String { get set }

  /// The classification of User
  var type: String? { get set }

  /// The current state of the User
  var status: String? { get set }

  /// The external identifier for the object
  var externalId: String? { get set }

  /// The profile URL for the object
  var profileURL: String? { get set }

  /// The email address of the object
  var email: String? { get set }

  /// The last updated timestamp for the object
  var updated: Date? { get set }

  /// The caching identifier for the object
  var eTag: String? { get set }

  /// All custom fields set on the object
  var custom: [String: JSONCodableScalar]? { get set }
}
```

##### Failure

An `Error` describing the failure.

#### Sample code

```swift
// Set user metadata for a specific identifier
let userMetadataToSet = PubNubUserMetadataBase(
  metadataId: "some-id",
  name: "Some User",
  custom: ["department": "Engineering"]
)

pubnub.setUserMetadata(userMetadataToSet) { result in
  switch result {
  case let .success(userMetadata):
    print("The metadata for `\(userMetadata.metadataId)`: \(userMetadata)")
  case let .failure(error):
    print("Create request failed with error: \(error.localizedDescription)")
  }
}
```

### Remove user metadata

Removes the metadata from a specified UUID.

#### Method(s)

To `Remove User Metadata` you can use the following method(s) in the Swift SDK:

```swift
func removeUserMetadata(
    _ metadataId: String?,
    custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
    completion: ((Result<String, Error>) -> Void)?
)
```

| Parameter | Description |
| --- | --- |
| `metadataId` *Type: StringDefault: n/a | Unique User Metadata identifier. If not supplied, then it will use the request configuration and then the default configuration. |
| `custom`Type: [PubNub.RequestConfiguration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration)Default: `PubNub.RequestConfiguration()` | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the [Request Configuration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration) section. |
| `completion`Type: `((Result<String, Error>) -> Void)?`Default: `nil` | The async `Result` of the method call. |

#### Completion handler result

##### Success

The User identifier of the removed object.

##### Failure

An `Error` describing the failure

#### Sample code

```swift
// Remove user metadata for a specific identifier
pubnub.removeUserMetadata("some-id") { result in
  switch result {
  case let .success(metadataId):
    print("The metadata has been removed for the identifier `\(metadataId)`")
  case let .failure(error):
    print("Delete request failed with error: \(error.localizedDescription)")
  }
}
```

## Channel

### Get metadata for all channels

Returns a paginated list of Channel Metadata objects, optionally including the custom data object for each.

:::warning Required keyset configuration
To get all channel and user metadata, you must uncheck the
Disallow Get All Channel Metadata
and
Disallow Get All User Metadata
checkboxes in the App Context section of your keyset configuration in the
[Admin Portal](https://admin.pubnub.com)
.
:::

#### Method(s)

To `Get All Channel Metadata` you can use the following method(s) in the Swift SDK:

```swift
func allChannelMetadata(
    include: PubNub.IncludeFields = PubNub.IncludeFields(),
    filter: String? = nil,
    sort: [PubNub.ObjectSortField] = [],
    limit: Int? = 100,
    page: PubNubHashedPage? = Page(),
    custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
    completion: ((Result<(channels: [PubNubChannelMetadata], next: PubNubHashedPage?), Error>) -> Void)?
)
```

| Parameter | Description |
| --- | --- |
| `include`Type: PubNub.IncludeFieldsDefault: `PubNub.IncludeFields()` | Whether to include additional fields. |
| `filter`Type: String?Default: `nil` | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined [here](https://www.pubnub.com/docs/general/metadata/filtering). |
| `sort`Type: [PubNub.ObjectSortField]Default: `[]` | List of properties to sort response objects. The following properties are valid for sorting: `.id`, `.name`, `.type`, `.status`, and `.updated`. |
| `limit`Type: Int?Default: 100 | The number of objects to retrieve at a time. |
| `page`Type: PubNubHashedPage?Default: `PubNub.Page()` | The paging object used for pagination. |
| `custom`Type: [PubNub.RequestConfiguration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration)Default: `PubNub.RequestConfiguration()` | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the [Request Configuration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration) section. |
| `completion`Type: `((Result<(channels: [PubNubChannelMetadata], next: PubNubHashedPage?), Error>) -> Void)?`Default: `nil` | The async `Result` of the method call. |

#### Completion handler result

##### Success

A `Tuple` containing an `Array` of `PubNubChannelMetadata`, and the next pagination `PubNubHashedPage` (if one exists).

```swift
public protocol PubNubChannelMetadata {

  /// The unique identifier of the Channel
  var metadataId: String { get }

  /// The name of the Channel
  var name: String { get set }

  /// The classification of ChannelMetadata
  var type: String? { get set }
  
  /// The current state of the ChannelMetadata
  var status: String? { get set }

  /// Text describing the purpose of the channel
  var channelDescription: String? { get set }

  /// The last updated timestamp for the object
  var updated: Date? { get set }

  /// The caching identifier for the object
  var eTag: String? { get set }

  /// All custom fields set on the object
  var custom: [String: JSONCodableScalar]? { get set }
}
```

```swift
public protocol PubNubHashedPage {

  /// The hash value representing the next set of data
  var start: String? { get }

  /// The hash value representing the previous set of data
  var end: String? { get }

  /// The total count of all objects withing range
  var totalCount: Int? { get }
}
```

##### Failure

An `Error` describing the failure.

#### Sample code

```swift
// Retrieve all channel metadata
pubnub.allChannelMetadata { result in
  switch result {
  case let .success(response):
    print("The channel metadata objects \(response.channels)")
    print("The next page used for pagination: \(String(describing: response.next))")
  case let .failure(error):
    print("Fetch All request failed with error: \(error.localizedDescription)")
  }
}
```

### Get channel metadata

Returns metadata for the specified Channel, optionally including the custom data object for each.

#### Method(s)

To `Get Channel Metadata` you can use the following method(s) in the Swift SDK:

```swift
func fetchChannelMetadata(
    _ metadataId: String?,
    include: PubNub.ChannelIncludeFields = PubNub.ChannelIncludeFields(),
    custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
    completion: ((Result<PubNubChannelMetadata, Error>) -> Void)?
)
```

| Parameter | Description |
| --- | --- |
| `channel` *Type: StringDefault: n/a | Unique Channel Metadata identifier. If not supplied, then it will use the request configuration and then the default configuration. |
| `include`Type: [PubNub.ChannelIncludeFields](#channelincludefields)Default: `PubNub.ChannelIncludeFields()` | Whether to include additional fields. |
| `custom`Type: [PubNub.RequestConfiguration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration)Default: `PubNub.RequestConfiguration()` | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the [Request Configuration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration) section. |
| `completion`Type: `((Result<PubNubChannelMetadata, Error>) -> Void)?`Default: `nil` | The async `Result` of the method call. |

#### ChannelIncludeFields

`PubNub.ChannelIncludeFields` is a struct that defines which additional fields should be included in the response when fetching channel metadata. It provides the same control options as `PubNub.UserIncludeFields` but for channel-specific operations.

| Property | Description |
| --- | --- |
| `custom`Type: `Bool`Default: `true` | Whether to include the custom dictionary for the channel metadata object |
| `type`Type: `Bool`Default: `true` | Whether to include the type field for the channel metadata object |
| `status`Type: `Bool`Default: `true` | Whether to include the status field for the channel metadata object |
| `totalCount`Type: `Bool`Default: `true` | Whether to include the total count of how many channel objects are available |

#### Completion handler result

##### Success

The `PubNubChannelMetadata` object belonging to the identifier.

```swift
public protocol PubNubChannelMetadata {

  /// The unique identifier of the Channel
  var metadataId: String { get }

  /// The name of the Channel
  var name: String { get set }

  /// The classification of ChannelMetadata
  var type: String? { get set }
  
  /// The current state of the ChannelMetadata
  var status: String? { get set }

  /// Text describing the purpose of the channel
  var channelDescription: String? { get set }

  /// The last updated timestamp for the object
  var updated: Date? { get set }

  /// The caching identifier for the object
  var eTag: String? { get set }

  /// All custom fields set on the object
  var custom: [String: JSONCodableScalar]? { get set }
}
```

##### Failure

An `Error` describing the failure.

#### Sample code

```swift
// Retrieve channel metadata for a specific identifier
pubnub.fetchChannelMetadata("some-channel-id") { result in
  switch result {
  case let .success(channelMetadata):
    print("The metadata for `\(channelMetadata.metadataId)`: \(channelMetadata)")
  case let .failure(error):
    print("Fetch request failed with error: \(error.localizedDescription)")
  }
}
```

### Set channel metadata

:::warning Unsupported partial updates of custom metadata
The value of the custom metadata parameter sent in this method always overwrites the value stored on PubNub servers. If you want to add new custom data to an existing one, you must:
1. Get the existing metadata and store it locally.
2. Append the new custom metadata to the existing one.
3. Set the entire updated custom object.
:::

Set metadata for a Channel in the database, optionally including the custom data object for each.

#### Method(s)

To `Set Channel Metadata` you can use the following method(s) in the Swift SDK:

```swift
func setChannelMetadata(
    _ metadata: PubNubChannelMetadata,
    ifMatchesEtag: String? = nil
    include: PubNub.ChannelIncludeFields = PubNub.ChannelIncludeFields(),
    custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
    completion: ((Result<PubNubChannelMetadata, Error>) -> Void)?
)
```

| Parameter | Description |
| --- | --- |
| `metadata` *Type: PubNubChannelMetadataDefault: n/a | Channel Metadata to set. |
| `ifMatchesEtag`Type: StringDefault: n/a | The entity tag to be used to ensure updates only happen if the object hasn't been modified since it was read. Use the eTag you received from an applicable get metadata method to check against the server entity tag. If the eTags don't match, an HTTP 412 error is thrown. |
| `include`Type: [PubNub.ChannelIncludeFields](#channelincludefields)Default: `PubNub.ChannelIncludeFields()` | Whether to include additional fields. |
| `custom`Type: [PubNub.RequestConfiguration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration)Default: `PubNub.RequestConfiguration()` | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the [Request Configuration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration) section. |
| `completion`Type: `((Result<PubNubChannelMetadata, Error>) -> Void)?`Default: `nil` | The async `Result` of the method call. |

:::tip API limits
To learn about the maximum length of parameters used to set channel metadata, refer to [REST API docs](https://www.pubnub.com/docs/sdks/rest-api/set-channel-metadata).
:::

#### Completion handler result

##### Success

The `PubNubChannelMetadata` object belonging to the identifier.

```swift
public protocol PubNubChannelMetadata {

  /// The unique identifier of the Channel
  var metadataId: String { get }

  /// The name of the Channel
  var name: String { get set }

  /// The classification of ChannelMetadata
  var type: String? { get set }
  
  /// The current state of the ChannelMetadata
  var status: String? { get set }

  /// Text describing the purpose of the channel
  var channelDescription: String? { get set }

  /// The last updated timestamp for the object
  var updated: Date? { get set }

  /// The caching identifier for the object
  var eTag: String? { get set }

  /// All custom fields set on the object
  var custom: [String: JSONCodableScalar]? { get set }
}
```

##### Failure

An `Error` describing the failure.

#### Sample code

```swift
// Set channel metadata for a specific identifier
let channelMetadataToSet = PubNubChannelMetadataBase(
  metadataId: "some-channel-id",
  name: "Channel Name"
)

pubnub.setChannelMetadata(channelMetadataToSet) { result in
  switch result {
  case let .success(channelMetadata):
    print("The metadata for `\(channelMetadata.metadataId)`: \(channelMetadata)")
  case let .failure(error):
    print("Create request failed with error: \(error.localizedDescription)")
  }
}
```

#### Other examples

##### Iteratively update existing metadata

```swift
// Simulates a reference to already fetched channel metadata
var existingChannelMetadata = PubNubChannelMetadataBase(
  metadataId: "yourChannelMetadataId",
  name: "Offtopic",
  type: "Miscellaneous",
  status: "active",
  custom: ["admin": "John Stones"]
)

// Modify properties directly, such as updating `custom` and `name`
existingChannelMetadata.custom = ["admin": "Charles Dawson"]
existingChannelMetadata.name = "Unrelated"

// When you're ready, set the updated metadata on the server to persist the changes:
pubnub.setChannelMetadata(existingChannelMetadata) { result in
  switch result {
  case let .success(metadata):
    print("Did successfully set channel metadata with \(metadata.metadataId)")
  case let .failure(error):
    print("Unexpected error along the way: \(error)")
  }
}
```

### Remove channel metadata

Removes the metadata from a specified channel.

#### Method(s)

To `Remove Channel Metadata` you can use the following method(s) in the Swift SDK:

```swift
func removeChannelMetadata(
    _ metadataId: String?,
    custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
    completion: ((Result<String, Error>) -> Void)?
)
```

| Parameter | Description |
| --- | --- |
| `channel` *Type: StringDefault: n/a | Unique Channel Metadata identifier. If not supplied, then it will use the request configuration and then the default configuration. |
| `custom`Type: [PubNub.RequestConfiguration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration)Default: `PubNub.RequestConfiguration()` | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the [Request Configuration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration) section. |
| `completion`Type: `((Result<PubNubChannelMetadata, Error>) -> Void)?`Default: `nil` | The async `Result` of the method call. |

#### Completion handler result

##### Success

The Channel identifier of the removed object.

##### Failure

An `Error` describing the failure.

#### Sample code

```swift
// Remove channel metadata for a specific identifier
pubnub.removeChannelMetadata("some-channel-id") { result in
  switch result {
  case let .success(metadataId):
    print("The metadata has been removed for the channel `\(metadataId)`")
  case let .failure(error):
    print("Delete request failed with error: \(error.localizedDescription)")
  }
}
```

## Channel memberships

### Get channel memberships

The method returns a list of channel memberships for a user. This method doesn't return a user's subscriptions.

#### Method(s)

To `Get Memberships` you can use the following method(s) in the Swift SDK:

To `Get Channel Memberships` you can use the following method(s) in the Swift SDK:

```swift
func fetchMemberships(
    userId: String?,
    include: PubNub.MembershipInclude = PubNub.MembershipInclude(),
    filter: String? = nil,
    sort: [PubNub.MembershipSortField] = [],
    limit: Int? = 100,
    page: PubNubHashedPage? = Page(),
    custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
    completion: ((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)?
)
```

| Parameter | Description |
| --- | --- |
| `userId` *Type: StringDefault: n/a | Unique User Metadata identifier. If not supplied, then it will use the request configuration and then the default configuration. |
| `include`Type: [PubNub.MembershipInclude](#membershipinclude)Default: `PubNub.MembershipInclude()` | Whether to include additional fields. |
| `filter`Type: String?Default: `nil` | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined [here](https://www.pubnub.com/docs/general/metadata/filtering). |
| `sort`Type: [MembershipSortField]Default: `[]` | List of properties to sort response objects. The following properties are valid for sorting: `.object(.id)`, `.object(.name)`, `.object(.type)`, `.object(.status)`, `.object(.updated)`, `.type`, `.status`, `.updated`. |
| `limit`Type: Int?Default: 100 | The number of objects to retrieve at a time. |
| `page`Type: PubNubHashedPage?Default: `PubNub.Page()` | The paging object used for pagination. |
| `custom`Type: [PubNub.RequestConfiguration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration)Default: `PubNub.RequestConfiguration()` | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the [Request Configuration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration) section. |
| `completion`Type: `((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)?`Default: `nil` | The async `Result` of the method call. |

#### MembershipInclude

`PubNub.MembershipInclude` is a struct that defines which additional fields should be included in the response when fetching user membership data (channels a user belongs to). It provides granular control over both membership fields and associated channel metadata fields.

| Property | Description |
| --- | --- |
| `customFields`Type: `Bool`Default: `true` | Whether to include the custom dictionary for the membership object |
| `channelFields`Type: `Bool`Default: `false` | Whether to include the full PubNubChannelMetadata instance in the membership |
| `typeField`Type: `Bool`Default: `true` | Whether to include the type field of the membership object |
| `statusField`Type: `Bool`Default: `true` | Whether to include the status field of the membership object |
| `channelTypeField`Type: `Bool`Default: `false` | Whether to include the type field of the associated channel metadata |
| `channelStatusField`Type: `Bool`Default: `false` | Whether to include the status field of the associated channel metadata |
| `channelCustomFields`Type: `Bool`Default: `false` | Whether to include the custom dictionary of the associated channel metadata |
| `totalCount`Type: `Bool`Default: `false` | Whether to include the total count of how many membership objects are available |

#### Completion handler result

##### Success

A `Tuple` containing an `Array` of `PubNubMembershipMetadata`, and the next pagination `PubNubHashedPage` (if one exists).

```swift
public protocol PubNubMembershipMetadata {

  /// The unique identifier of the associated User
  var userMetadataId: String { get }

  /// The unique identifier of the associated Channel
  var channelMetadataId: String { get }

  /// The current status of the MembershipMetadata
  var status: String? { get set }
  
  /// The current type of the MembershipMetadata
  var type: String? { get set }

  /// The associated User metadata
  var user: PubNubUserMetadata? { get set }

  /// The associated Channel metadata
  var channel: PubNubChannelMetadata? { get set }

  /// The last updated timestamp for the object
  var updated: Date? { get set }

  /// The caching identifier for the object
  var eTag: String? { get set }

  /// All custom fields set on the object
  var custom: [String: JSONCodableScalar]? { get set }
}
```

```swift
public protocol PubNubHashedPage {

  /// The hash value representing the next set of data
  var start: String? { get }

  /// The hash value representing the previous set of data
  var end: String? { get }

  /// The total count of all objects withing range
  var totalCount: Int? { get }
}
```

##### Failure

An `Error` describing the failure.

#### Sample code

* Fetch and handle user channel memberships.

```swift
// Retrieve channel memberships for a specific user identifier
pubnub.fetchMemberships(userId: "some-user-id") { result in
  switch result {
  case let .success(response):
    print("The channel memberships for the userId: \(response.memberships)")
    print("The next page used for pagination: \(String(describing: response.next))")
  case let .failure(error):
    print("Fetch Memberships request failed with error: \(error.localizedDescription)")
  }
}
```

* Return sorted channel memberships for the given user ID.

```swift
// Retrieve channel memberships for a specific user identifier and sort them by name
pubnub.fetchMemberships(
  userId: "someUserId",
  sort: [.init(property: .object(.name))]
) { result in
  switch result {
  case let .success(response):
    print("List of channel memberships: \(response.memberships)")
    print("The next page used for pagination: \(String(describing: response.next))")
  case let .failure(error):
    print("An error occurred: \(error.localizedDescription)")
  }
}
```

### Set channel memberships

Set channel memberships for a User.

#### Method(s)

To `Set Channel Memberships` you can use the following method(s) in the Swift SDK:

```swift
func setMemberships(
    userId metadataId: String?,
    channels memberships: [PubNubMembershipMetadata],
    include: PubNub.MembershipInclude = PubNub.MembershipInclude(),
    filter: String? = nil,
    sort: [PubNub.MembershipSortField] = [],
    limit: Int? = 100,
    page: PubNubHashedPage? = Page(),
    custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
    completion: ((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)?
)
```

| Parameter | Description |
| --- | --- |
| `userId` *Type: StringDefault: n/a | Unique User Metadata identifier. If not supplied, then it will use the request configuration and then the default configuration. |
| `channels` *Type: [PubNubMembershipMetadata]Default: n/a | Array of `PubNubMembershipMetadata` with the `PubNubChannelMetadata` or `channelMetadataId` provided. |
| `include`Type: [PubNub.MembershipInclude](#membershipinclude)Default: `PubNub.MembershipInclude()` | Whether to include additional fields. |
| `filter`Type: String?Default: `nil` | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined [here](https://www.pubnub.com/docs/general/metadata/filtering). |
| `sort`Type: [PubNub.MembershipSortField]Default: `[]` | List of properties to sort response objects. The following properties are valid for sorting: `.object(.id)`, `.object(.name)`, `.object(.type)`, `.object(.status)`, `.object(.updated)`, `.type`, `.status`, and `.updated`. |
| `limit`Type: Int?Default: 100 | The number of objects to retrieve at a time. |
| `page`Type: PubNubHashedPage?Default: `PubNub.Page()` | The paging object used for pagination. |
| `custom`Type: [PubNub.RequestConfiguration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration)Default: `PubNub.RequestConfiguration()` | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the [Request Configuration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration) section. |
| `completion`Type: `((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)?`Default: `nil` | The async `Result` of the method call. |

:::tip API limits
To learn about the maximum length of parameters used to set channel membership metadata, refer to [REST API docs](https://www.pubnub.com/docs/sdks/rest-api/set-membership-metadata).
:::

#### Completion handler result

##### Success

A `Tuple` containing an `Array` of `PubNubMembershipMetadata`, and the next pagination `PubNubHashedPage` (if one exists).

```swift
public protocol PubNubMembershipMetadata {

  /// The unique identifier of the associated User
  var userMetadataId: String { get }

  /// The unique identifier of the associated Channel
  var channelMetadataId: String { get }

  /// The current status of the MembershipMetadata
  var status: String? { get set }
  
  /// The current type of the MembershipMetadata
  var type: String? { get set }

  /// The associated User metadata
  var user: PubNubUserMetadata? { get set }

  /// The associated Channel metadata
  var channel: PubNubChannelMetadata? { get set }

  /// The last updated timestamp for the object
  var updated: Date? { get set }

  /// The caching identifier for the object
  var eTag: String? { get set }

  /// All custom fields set on the object
  var custom: [String: JSONCodableScalar]? { get set }
}
```

```swift
public protocol PubNubHashedPage {

  /// The hash value representing the next set of data
  var start: String? { get }

  /// The hash value representing the previous set of data
  var end: String? { get }

  /// The total count of all objects withing range
  var totalCount: Int? { get }
}
```

##### Failure

An `Error` describing the failure.

#### Sample code

```swift
let membershipToSet = PubNubMembershipMetadataBase(
  userMetadataId: "my_user",
  channelMetadataId: "my_channel"
)

// Set channel memberships for a specific user identifier
pubnub.setMemberships(
  userId: membershipToSet.userMetadataId,
  channels: [membershipToSet]
) { result in
  switch result {
  case let .success(response):
    print("The channel memberships for the userId: \(response.memberships)")
    print("The next page used for pagination: \(String(describing: response.next))")
  case let .failure(error):
    print("Update Memberships request failed with error: \(error.localizedDescription)")
  }
}
```

### Remove channel memberships

Remove channel memberships for a User.

#### Method(s)

To `Remove Channel Memberships` you can use the following method(s) in the Swift SDK:

```swift
func removeMemberships(
    userId metadataId: String?,
    channels memberships: [PubNubMembershipMetadata],
    include: PubNub.MembershipInclude = PubNub.MembershipInclude(),
    filter: String? = nil,
    sort: [PubNub.MembershipSortField] = [],
    limit: Int? = 100,
    page: PubNubHashedPage? = Page(),
    custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
    completion: ((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)?
)
```

| Parameter | Description |
| --- | --- |
| `userId` *Type: StringDefault: n/a | Unique User Metadata identifier. If not supplied, then it will use the request configuration and then the default configuration. |
| `channels` *Type: [PubNubMembershipMetadata]Default: n/a | Array of `PubNubMembershipMetadata` with the `PubNubChannelMetadata` or `channelMetadataId` provided. |
| `include`Type: [PubNub.MembershipInclude](#membershipinclude)Default: `PubNub.MembershipInclude()` | Whether to include additional fields. |
| `filter`Type: String?Default: `nil` | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined [here](https://www.pubnub.com/docs/general/metadata/filtering). |
| `sort`Type: [PubNub.MembershipSortField]Default: `[]` | List of properties to sort response objects. The following properties are valid for sorting: `.object(.id)`, `.object(.name)`, `.object(.type)`, `.object(.status)`, `.object(.updated)`, `.type`, `.status`, and `.updated`. |
| `limit`Type: Int?Default: 100 | The number of objects to retrieve at a time. |
| `page`Type: PubNubHashedPage?Default: `PubNub.Page()` | The paging object used for pagination. |
| `custom`Type: [PubNub.RequestConfiguration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration)Default: `PubNub.RequestConfiguration()` | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the [Request Configuration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration) section. |
| `completion`Type: `((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)?`Default: `nil` | The async `Result` of the method call. |

#### Completion handler result

##### Success

A `Tuple` containing an `Array` of `PubNubMembershipMetadata`, and the next pagination `PubNubHashedPage` (if one exists).

```swift
public protocol PubNubMembershipMetadata {

  /// The unique identifier of the associated User
  var userMetadataId: String { get }

  /// The unique identifier of the associated Channel
  var channelMetadataId: String { get }

  /// The current status of the MembershipMetadata
  var status: String? { get set }
  
  /// The current type of the MembershipMetadata
  var type: String? { get set }

  /// The associated User metadata
  var user: PubNubUserMetadata? { get set }

  /// The associated Channel metadata
  var channel: PubNubChannelMetadata? { get set }

  /// The last updated timestamp for the object
  var updated: Date? { get set }

  /// The caching identifier for the object
  var eTag: String? { get set }

  /// All custom fields set on the object
  var custom: [String: JSONCodableScalar]? { get set }
}
```

```swift
public protocol PubNubHashedPage {

  /// The hash value representing the next set of data
  var start: String? { get }

  /// The hash value representing the previous set of data
  var end: String? { get }

  /// The total count of all objects withing range
  var totalCount: Int? { get }
}
```

##### Failure

An `Error` describing the failure.

#### Sample code

```swift
let membershipToRemove = PubNubMembershipMetadataBase(
  userMetadataId: "my_user",
  channelMetadataId: "my_channel"
)

// Remove channel memberships for a specific user identifier
pubnub.removeMemberships(
  userId: membershipToRemove.userMetadataId,
  channels: [membershipToRemove]
) { result in
  switch result {
  case let .success(response):
    print("The channel memberships for the userId: \(response.memberships)")
    print("The next page used for pagination: \(String(describing: response.next))")
  case let .failure(error):
    print("Update Memberships request failed with error: \(error.localizedDescription)")
  }
}
```

## Channel members

### Get channel members

The method returns a list of members in a channel. The list will include user metadata for members that have additional metadata stored in the database.

#### Method(s)

To `Get Channel Members` you can use the following method(s) in the Swift SDK:

```swift
func fetchMembers(
    channel: String?,
    include: PubNub.MemberInclude = PubNub.MemberInclude(),
    filter: String? = nil,
    sort: [PubNub.MembershipSortField] = [],
    limit: Int? = 100,
    page: PubNubHashedPage? = Page(),
    custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
    completion: ((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)?
)
```

| Parameter | Description |
| --- | --- |
| `channel` *Type: StringDefault: n/a | Unique Channel Metadata identifier. |
| `include`Type: [PubNub.MemberInclude](#memberinclude)Default: `PubNub.MemberInclude()` | Whether to include additional fields. |
| `filter`Type: String?Default: `nil` | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined [here](https://www.pubnub.com/docs/general/metadata/filtering). |
| `sort`Type: [PubNub.MembershipSortField]Default: `[]` | List of properties to sort response objects. The following properties are valid for sorting: `.object(.id)`, `.object(.name)`, `.object(.type)`, `.object(.status)`, `.object(.updated)`, `.type`, `.status`, and `.updated`. |
| `limit`Type: Int?Default: 100 | The number of objects to retrieve at a time. |
| `page`Type: PubNubHashedPage?Default: `PubNub.Page()` | The paging object used for pagination. |
| `custom`Type: [PubNub.RequestConfiguration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration)Default: `PubNub.RequestConfiguration()` | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the [Request Configuration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration) section. |
| `completion`Type: `((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)?`Default: `nil` | The async `Result` of the method call. |

#### MemberInclude

`PubNub.MemberInclude` is a struct that defines which additional fields should be included in the response when fetching channel member data (users that belong to a channel). It provides granular control over both membership fields and associated user metadata fields.

| Property | Description |
| --- | --- |
| `customFields`Type: `Bool`Default: `true` | Whether to include the custom dictionary for the membership object |
| `uuidFields`Type: `Bool`Default: `false` | Whether to include the full PubNubUserMetadata instance in the membership |
| `statusField`Type: `Bool`Default: `true` | Whether to include the status field of the membership object |
| `typeField`Type: `Bool`Default: `true` | Whether to include the type field of the membership object |
| `uuidTypeField`Type: `Bool`Default: `false` | Whether to include the type field of the associated user metadata |
| `uuidStatusField`Type: `Bool`Default: `false` | Whether to include the status field of the associated user metadata |
| `uuidCustomFields`Type: `Bool`Default: `false` | Whether to include the custom dictionary of the associated user metadata |
| `totalCount`Type: `Bool`Default: `false` | Whether to include the total count of how many member objects are available |

#### Completion handler result

##### Success

A `Tuple` containing an `Array` of `PubNubMembershipMetadata`, and the next pagination `PubNubHashedPage` (if one exists).

```swift
public protocol PubNubMembershipMetadata {

  /// The unique identifier of the associated User
  var userMetadataId: String { get }

  /// The unique identifier of the associated Channel
  var channelMetadataId: String { get }

  /// The current status of the MembershipMetadata
  var status: String? { get set }
  
  /// The current type of the MembershipMetadata
  var type: String? { get set }

  /// The associated User metadata
  var user: PubNubUserMetadata? { get set }

  /// The associated Channel metadata
  var channel: PubNubChannelMetadata? { get set }

  /// The last updated timestamp for the object
  var updated: Date? { get set }

  /// The caching identifier for the object
  var eTag: String? { get set }

  /// All custom fields set on the object
  var custom: [String: JSONCodableScalar]? { get set }
}
```

```swift
public protocol PubNubHashedPage {

  /// The hash value representing the next set of data
  var start: String? { get }

  /// The hash value representing the previous set of data
  var end: String? { get }

  /// The total count of all objects withing range
  var totalCount: Int? { get }
}
```

##### Failure

An `Error` describing the failure.

#### Sample code

```swift
// Retrieve members for a specific channel
pubnub.fetchMembers(channel: "my_channel_id") { result in
  switch result {
  case let .success(response):
    print("The user members for the channel: \(response.memberships)")
    print("The next page used for pagination: \(String(describing: response.next))")
  case let .failure(error):
    print("Fetch Memberships request failed with error: \(error.localizedDescription)")
  }
}
```

### Set channel members

This method sets members in a channel.

#### Method(s)

To `Set Channel Members` you can use the following method(s) in the Swift SDK:

```swift
func setMembers(
    channel metadataId: String,
    users members: [PubNubMembershipMetadata],
    include: PubNub.MemberInclude = PubNub.MemberInclude(),
    filter: String? = nil,
    sort: [PubNub.MembershipSortField] = [],
    limit: Int? = 100,
    page: PubNubHashedPage? = Page(),
    custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
    completion: ((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)?
)
```

| Parameter | Description |
| --- | --- |
| `channel` *Type: StringDefault: n/a | Unique Channel identifier. |
| `users` *Type: [PubNubMembershipMetadata]Default: n/a | Array of `PubNubMembershipMetadata` with the `PubNubUserMetadata` or `userMetadataId` provided. |
| `include`Type: [PubNub.MemberInclude](#memberinclude)Default: `PubNub.MemberInclude()` | Whether to include additional fields. |
| `filter`Type: String?Default: `nil` | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined [here](https://www.pubnub.com/docs/general/metadata/filtering). |
| `sort`Type: [PubNub.MembershipSortField]Default: `[]` | List of properties to sort response objects. The following properties are valid for sorting: `.object(.id)`, `.object(.name)`, `.object(.type)`, `.object(.status)`, `.object(.updated)`, `.type`, `.status`, and `.updated`. |
| `limit`Type: Int?Default: 100 | The number of objects to retrieve at a time. |
| `page`Type: PubNubHashedPage?Default: `PubNub.Page()` | The paging object used for pagination. |
| `custom`Type: [PubNub.RequestConfiguration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration)Default: `PubNub.RequestConfiguration()` | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the [Request Configuration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration) section. |
| `completion`Type: `((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)?`Default: `nil` | The async `Result` of the method call. |

:::tip API limits
To learn about the maximum length of parameters used to set channel members metadata, refer to [REST API docs](https://www.pubnub.com/docs/sdks/rest-api/set-channel-members-metadata).
:::

#### Completion handler result

##### Success

A `Tuple` containing an `Array` of `PubNubMembershipMetadata`, and the next pagination `PubNubHashedPage` (if one exists).

```swift
public protocol PubNubMembershipMetadata {

  /// The unique identifier of the associated User
  var userdMetadataId: String { get }

  /// The unique identifier of the associated Channel
  var channelMetadataId: String { get }

  /// The current status of the MembershipMetadata
  var status: String? { get set }
  
  /// The current type of the MembershipMetadata
  var type: String? { get set }

  /// The associated User metadata
  var user: PubNubUserMetadata? { get set }

  /// The associated Channel metadata
  var channel: PubNubChannelMetadata? { get set }

  /// The last updated timestamp for the object
  var updated: Date? { get set }

  /// The caching identifier for the object
  var eTag: String? { get set }

  /// All custom fields set on the object
  var custom: [String: JSONCodableScalar]? { get set }
}
```

```swift
public protocol PubNubHashedPage {

  /// The hash value representing the next set of data
  var start: String? { get }

  /// The hash value representing the previous set of data
  var end: String? { get }

  /// The total count of all objects withing range
  var totalCount: Int? { get }
}
```

##### Failure

An `Error` describing the failure.

#### Sample code

```swift
let userToSet = PubNubMembershipMetadataBase(
  userMetadataId: "my_user",
  channelMetadataId: "my_channel"
)

// Set members for a specific channel
pubnub.setMembers(
  channel: userToSet.channelMetadataId,
  users: [userToSet]
) { result in
  switch result {
  case let .success(response):
    print("The user members for the channel: \(response.memberships)")
    print("The next page used for pagination: \(String(describing: response.next))")
  case let .failure(error):
    print("Update Memberships request failed with error: \(error.localizedDescription)")
  }
}
```

### Remove channel members

Remove members from a Channel.

#### Method(s)

To `Remove Channel Members` you can use the following method(s) in the Swift SDK:

```swift
func removeMembers(
    channel metadataId: String,
    users members: [PubNubMembershipMetadata],
    include: PubNub.MemberInclude = PubNub.MemberInclude(),
    filter: String? = nil,
    sort: [PubNub.MembershipSortField] = [],
    limit: Int? = 100,
    page: PubNubHashedPage? = Page(),
    custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
    completion: ((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)?
)
```

| Parameter | Description |
| --- | --- |
| `channel` *Type: StringDefault: n/a | Unique Channel identifier. |
| `uuids` *Type: [PubNubMembershipMetadata]Default: n/a | Array of `PubNubMembershipMetadata` with the `PubNubUserMetadata` or `userMetadataId` provided. |
| `include`Type: [PubNub.MemberInclude](#memberinclude)Default: `PubNub.MemberInclude()` | Whether to include additional fields. |
| `filter`Type: String?Default: `nil` | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined [here](https://www.pubnub.com/docs/general/metadata/filtering). |
| `sort`Type: [PubNub.MembershipSortField]Default: `[]` | List of properties to sort response objects. The following properties are valid for sorting: `.object(.id)`, `.object(.name)`, `.object(.type)`, `.object(.status)`, `.object(.updated)`, `.type`, `.status`, and `.updated`. |
| `limit`Type: Int?Default: 100 | The number of objects to retrieve at a time. |
| `page`Type: PubNubHashedPage?Default: `PubNub.Page()` | The paging object used for pagination. |
| `custom`Type: [PubNub.RequestConfiguration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration)Default: `PubNub.RequestConfiguration()` | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the [Request Configuration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration) section. |
| `completion`Type: `((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)?`Default: `nil` | The async `Result` of the method call. |

#### Completion handler result

##### Success

A `Tuple` containing an `Array` of `PubNubMembershipMetadata`, and the next pagination `PubNubHashedPage` (if one exists).

```swift
public protocol PubNubMembershipMetadata {

  /// The unique identifier of the associated User
  var userdMetadataId: String { get }

  /// The unique identifier of the associated Channel
  var channelMetadataId: String { get }

  /// The current status of the MembershipMetadata
  var status: String? { get set }
  
  /// The current type of the MembershipMetadata
  var type: String? { get set }

  /// The associated User metadata
  var user: PubNubUserMetadata? { get set }

  /// The associated Channel metadata
  var channel: PubNubChannelMetadata? { get set }

  /// The last updated timestamp for the object
  var updated: Date? { get set }

  /// The caching identifier for the object
  var eTag: String? { get set }

  /// All custom fields set on the object
  var custom: [String: JSONCodableScalar]? { get set }
}
```

```swift
public protocol PubNubHashedPage {

  /// The hash value representing the next set of data
  var start: String? { get }

  /// The hash value representing the previous set of data
  var end: String? { get }

  /// The total count of all objects withing range
  var totalCount: Int? { get }
}
```

##### Failure

An `Error` describing the failure.

#### Sample code

```swift
let memberToRemove = PubNubMembershipMetadataBase(
  userMetadataId: "my_user",
  channelMetadataId: "my_channel"
)

// Remove members for a specific channel
pubnub.removeMembers(
  channel: memberToRemove.channelMetadataId,
  users: [memberToRemove]
) { result in
  switch result {
  case let .success(response):
    print("The user members of the channel: \(response.memberships)")
    print("The next page used for pagination: \(String(describing: response.next))")
  case let .failure(error):
    print("Update Memberships request failed with error: \(error.localizedDescription)")
  }
}
```

## Terms in this document

* **Channel** - A pathway for sending and receiving messages between devices, created automatically when you first use it, that can handle any number of users and messages for different communication needs, like 1-1 text chats, group conversations, and other data streaming.
* **Channel pattern** - A way to group and analyze channel data to track performance metrics like message counts and user engagement over time with PubNub Insights.
* **User** - An individual or entity that interacts with a system, application, or service. In PubNub, a user typically refers to someone who sends or receives messages through the platform, identified by a unique user ID or username.
* **User ID** - UTF-8 encoded, unique string of up to 92 characters used to identify a single client (end user, device, or server) that connects to PubNub.