App Context API for Swift Native SDK
This page describes App Context (formerly Objects v2). To upgrade from Objects v1, refer to the migration guide.
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.
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.
Method(s)
To Get All User Metadata you can use the following method(s) in the Swift SDK:
1func allUserMetadata(
2 include: PubNub.UserIncludeFields = PubNub.UserIncludeFields(),
3 filter: String? = nil,
4 sort: [PubNub.ObjectSortField] = [],
5 limit: Int? = 100,
6 page: PubNubHashedPage? = Page(),
7 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
8 completion: ((Result<(users: [PubNubUserMetadata], next: PubNubHashedPage?), Error>) -> Void)?
9)
| Parameter | Description |
|---|---|
includeType: PubNub.UserIncludeFieldsDefault: PubNub.UserIncludeFields() | Whether to include additional fields. |
filterType: 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 |
sortType: [PubNub.ObjectSortField] Default: [] | List of properties to sort response objects. The following properties are valid for sorting: .id, .name, .type, .status, and .updated. |
pageType: PubNubHashedPage?Default: 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. |
limitType: Int? Default: 100 | The number of objects to retrieve at a time. |
customDefault: PubNub.RequestConfiguration() | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section. |
completionType: ((Result<(users: [PubNubUserMetadata], next: PubNubHashedPage?), Error>) -> Void)?Default: 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 |
|---|---|
customType: BoolDefault: true | Whether to include the custom dictionary for the user metadata object |
typeType: BoolDefault: true | Whether to include the type field for the user metadata object |
statusType: BoolDefault: true | Whether to include the status field for the user metadata object |
totalCountType: BoolDefault: 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).
1public protocol PubNubUserMetadata {
2
3 /// The unique identifier of the User
4 var metadataId: String { get }
5
6 /// The name of the User
7 var name: String { get set }
8
9 /// The classification of User
10 var type: String? { get set }
11
12 /// The current state of the User
13 var status: String? { get set }
14
15 /// The external identifier for the object
show all 32 lines1public protocol PubNubHashedPage {
2
3 /// The hash value representing the next set of data
4 var start: String? { get }
5
6 /// The hash value representing the previous set of data
7 var end: String? { get }
8
9 /// The total count of all objects withing range
10 var totalCount: Int? { get }
11}
Failure
An Error describing the failure.
Sample code
Reference code
1
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:
1func fetchUserMetadata(
2 _ metadataId: String?,
3 include: PubNub.UserIncludeFields = PubNub.UserIncludeFields(),
4 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
5 completion: ((Result<PubNubUserMetadata, Error>) -> Void)?
6)
| Parameter | Description |
|---|---|
metadataId *Type: String Default: n/a | Unique User Metadata identifier. If not supplied, then it will use the request configuration and then the default configuration. |
includeType: PubNub.UserIncludeFieldsDefault: PubNub.UserIncludeFields() | Whether to include additional fields. |
customDefault: PubNub.RequestConfiguration() | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section. |
completionType: ((Result<PubNubUserMetadata, Error>) -> Void)?Default: nil | The async Result of the method call. |
Completion handler result
Success
The PubNubUserMetadata object belonging to the identifier.
1public protocol PubNubUserMetadata {
2
3 /// The unique identifier of the User
4 var metadataId: String { get }
5
6 /// The name of the User
7 var name: String { get set }
8
9 /// The classification of User
10 var type: String? { get set }
11
12 /// The current state of the User
13 var status: String? { get set }
14
15 /// The external identifier for the object
show all 32 linesFailure
An Error describing the failure.
Sample code
1
Set user metadata
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:
- Get the existing metadata and store it locally.
- Append the new custom metadata to the existing one.
- 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:
1func setUserMetadata(
2 _ metadata: PubNubUserMetadata,
3 ifMatchesEtag: String? = nil,
4 include: PubNub.UserIncludeFields = PubNub.UserIncludeFields(),
5 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
6 completion: ((Result<PubNubUserMetadata, Error>) -> Void)?
7)
| Parameter | Description |
|---|---|
metadata *Type: PubNubUserMetadata Default: n/a | User Metadata to set. |
ifMatchesEtagType: String Default: 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. |
includeType: PubNub.UserIncludeFieldsDefault: PubNub.UserIncludeFields() | Whether to include additional fields. |
customDefault: PubNub.RequestConfiguration() | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section. |
completionType: ((Result<PubNubUserMetadata, Error>) -> Void)?Default: nil | The async Result of the method call. |
API limits
To learn about the maximum length of parameters used to set user metadata, refer to REST API docs.
Completion handler result
Success
The PubNubUserMetadata object belonging to the identifier.
1public protocol PubNubUserMetadata {
2
3 /// The unique identifier of the User
4 var metadataId: String { get }
5
6 /// The name of the User
7 var name: String { get set }
8
9 /// The classification of User
10 var type: String? { get set }
11
12 /// The current state of the User
13 var status: String? { get set }
14
15 /// The external identifier for the object
show all 32 linesFailure
An Error describing the failure.
Sample code
1
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:
1func removeUserMetadata(
2 _ metadataId: String?,
3 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
4 completion: ((Result<String, Error>) -> Void)?
5)
| Parameter | Description |
|---|---|
metadataId *Type: String Default: n/a | Unique User Metadata identifier. If not supplied, then it will use the request configuration and then the default configuration. |
customDefault: PubNub.RequestConfiguration() | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section. |
completionType: ((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
1
Channel
Get metadata for all channels
Returns a paginated list of Channel Metadata objects, optionally including the custom data object for each.
Method(s)
To Get All Channel Metadata you can use the following method(s) in the Swift SDK:
1func allChannelMetadata(
2 include: PubNub.IncludeFields = PubNub.IncludeFields(),
3 filter: String? = nil,
4 sort: [PubNub.ObjectSortField] = [],
5 limit: Int? = 100,
6 page: PubNubHashedPage? = Page(),
7 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
8 completion: ((Result<(channels: [PubNubChannelMetadata], next: PubNubHashedPage?), Error>) -> Void)?
9)
| Parameter | Description |
|---|---|
includeType: PubNub.IncludeFields Default: PubNub.IncludeFields() | Whether to include additional fields. |
filterType: 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. |
sortType: [PubNub.ObjectSortField] Default: [] | List of properties to sort response objects. The following properties are valid for sorting: .id, .name, .type, .status, and .updated. |
limitType: Int? Default: 100 | The number of objects to retrieve at a time. |
pageType: PubNubHashedPage? Default: PubNub.Page() | The paging object used for pagination. |
customDefault: PubNub.RequestConfiguration() | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section. |
completionType: ((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).
1public protocol PubNubChannelMetadata {
2
3 /// The unique identifier of the Channel
4 var metadataId: String { get }
5
6 /// The name of the Channel
7 var name: String { get set }
8
9 /// The classification of ChannelMetadata
10 var type: String? { get set }
11
12 /// The current state of the ChannelMetadata
13 var status: String? { get set }
14
15 /// Text describing the purpose of the channel
show all 26 lines1public protocol PubNubHashedPage {
2
3 /// The hash value representing the next set of data
4 var start: String? { get }
5
6 /// The hash value representing the previous set of data
7 var end: String? { get }
8
9 /// The total count of all objects withing range
10 var totalCount: Int? { get }
11}
Failure
An Error describing the failure.
Sample code
1
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:
1func fetchChannelMetadata(
2 _ metadataId: String?,
3 include: PubNub.ChannelIncludeFields = PubNub.ChannelIncludeFields(),
4 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
5 completion: ((Result<PubNubChannelMetadata, Error>) -> Void)?
6)
| Parameter | Description |
|---|---|
channel *Type: String Default: n/a | Unique Channel Metadata identifier. If not supplied, then it will use the request configuration and then the default configuration. |
includeDefault: PubNub.ChannelIncludeFields() | Whether to include additional fields. |
customDefault: PubNub.RequestConfiguration() | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section. |
completionType: ((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 |
|---|---|
customType: BoolDefault: true | Whether to include the custom dictionary for the channel metadata object |
typeType: BoolDefault: true | Whether to include the type field for the channel metadata object |
statusType: BoolDefault: true | Whether to include the status field for the channel metadata object |
totalCountType: BoolDefault: 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.
1public protocol PubNubChannelMetadata {
2
3 /// The unique identifier of the Channel
4 var metadataId: String { get }
5
6 /// The name of the Channel
7 var name: String { get set }
8
9 /// The classification of ChannelMetadata
10 var type: String? { get set }
11
12 /// The current state of the ChannelMetadata
13 var status: String? { get set }
14
15 /// Text describing the purpose of the channel
show all 26 linesFailure
An Error describing the failure.
Sample code
1
Set channel metadata
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:
- Get the existing metadata and store it locally.
- Append the new custom metadata to the existing one.
- 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:
1func setChannelMetadata(
2 _ metadata: PubNubChannelMetadata,
3 ifMatchesEtag: String? = nil
4 include: PubNub.ChannelIncludeFields = PubNub.ChannelIncludeFields(),
5 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
6 completion: ((Result<PubNubChannelMetadata, Error>) -> Void)?
7)
| Parameter | Description |
|---|---|
metadata *Type: PubNubChannelMetadata Default: n/a | Channel Metadata to set. |
ifMatchesEtagType: String Default: 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. |
includeDefault: PubNub.ChannelIncludeFields() | Whether to include additional fields. |
customDefault: PubNub.RequestConfiguration() | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section. |
completionType: ((Result<PubNubChannelMetadata, Error>) -> Void)?Default: nil | The async Result of the method call. |
API limits
To learn about the maximum length of parameters used to set channel metadata, refer to REST API docs.
Completion handler result
Success
The PubNubChannelMetadata object belonging to the identifier.
1public protocol PubNubChannelMetadata {
2
3 /// The unique identifier of the Channel
4 var metadataId: String { get }
5
6 /// The name of the Channel
7 var name: String { get set }
8
9 /// The classification of ChannelMetadata
10 var type: String? { get set }
11
12 /// The current state of the ChannelMetadata
13 var status: String? { get set }
14
15 /// Text describing the purpose of the channel
show all 26 linesFailure
An Error describing the failure.
Sample code
1
Other examples
Iteratively update existing metadata
1
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:
1func removeChannelMetadata(
2 _ metadataId: String?,
3 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
4 completion: ((Result<String, Error>) -> Void)?
5)
| Parameter | Description |
|---|---|
channel *Type: String Default: n/a | Unique Channel Metadata identifier. If not supplied, then it will use the request configuration and then the default configuration. |
customDefault: PubNub.RequestConfiguration() | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section. |
completionType: ((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
1
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:
1func fetchMemberships(
2 userId: String?,
3 include: PubNub.MembershipInclude = PubNub.MembershipInclude(),
4 filter: String? = nil,
5 sort: [PubNub.MembershipSortField] = [],
6 limit: Int? = 100,
7 page: PubNubHashedPage? = Page(),
8 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
9 completion: ((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)?
10)
| Parameter | Description |
|---|---|
userId *Type: String Default: n/a | Unique User Metadata identifier. If not supplied, then it will use the request configuration and then the default configuration. |
includeType: PubNub.MembershipIncludeDefault: PubNub.MembershipInclude() | Whether to include additional fields. |
filterType: 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. |
sortType: [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. |
limitType: Int? Default: 100 | The number of objects to retrieve at a time. |
pageType: PubNubHashedPage? Default: PubNub.Page() | The paging object used for pagination. |
customDefault: PubNub.RequestConfiguration() | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section. |
completionType: ((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 |
|---|---|
customFieldsType: BoolDefault: true | Whether to include the custom dictionary for the membership object |
channelFieldsType: BoolDefault: false | Whether to include the full PubNubChannelMetadata instance in the membership |
typeFieldType: BoolDefault: true | Whether to include the type field of the membership object |
statusFieldType: BoolDefault: true | Whether to include the status field of the membership object |
channelTypeFieldType: BoolDefault: false | Whether to include the type field of the associated channel metadata |
channelStatusFieldType: BoolDefault: false | Whether to include the status field of the associated channel metadata |
channelCustomFieldsType: BoolDefault: false | Whether to include the custom dictionary of the associated channel metadata |
totalCountType: BoolDefault: 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).
1public protocol PubNubMembershipMetadata {
2
3 /// The unique identifier of the associated User
4 var userMetadataId: String { get }
5
6 /// The unique identifier of the associated Channel
7 var channelMetadataId: String { get }
8
9 /// The current status of the MembershipMetadata
10 var status: String? { get set }
11
12 /// The current type of the MembershipMetadata
13 var type: String? { get set }
14
15 /// The associated User metadata
show all 29 lines1public protocol PubNubHashedPage {
2
3 /// The hash value representing the next set of data
4 var start: String? { get }
5
6 /// The hash value representing the previous set of data
7 var end: String? { get }
8
9 /// The total count of all objects withing range
10 var totalCount: Int? { get }
11}
Failure
An Error describing the failure.
Sample code
- Fetch and handle user channel memberships.
1
- Return sorted channel memberships for the given user ID.
1
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:
1func setMemberships(
2 userId metadataId: String?,
3 channels memberships: [PubNubMembershipMetadata],
4 include: PubNub.MembershipInclude = PubNub.MembershipInclude(),
5 filter: String? = nil,
6 sort: [PubNub.MembershipSortField] = [],
7 limit: Int? = 100,
8 page: PubNubHashedPage? = Page(),
9 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
10 completion: ((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)?
11)
| Parameter | Description |
|---|---|
userId *Type: String Default: 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. |
includeType: PubNub.MembershipIncludeDefault: PubNub.MembershipInclude() | Whether to include additional fields. |
filterType: 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. |
sortType: [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. |
limitType: Int? Default: 100 | The number of objects to retrieve at a time. |
pageType: PubNubHashedPage? Default: PubNub.Page() | The paging object used for pagination. |
customDefault: PubNub.RequestConfiguration() | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section. |
completionType: ((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)?Default: nil | The async Result of the method call. |
API limits
To learn about the maximum length of parameters used to set channel membership metadata, refer to REST API docs.
Completion handler result
Success
A Tuple containing an Array of PubNubMembershipMetadata, and the next pagination PubNubHashedPage (if one exists).
1public protocol PubNubMembershipMetadata {
2
3 /// The unique identifier of the associated User
4 var userMetadataId: String { get }
5
6 /// The unique identifier of the associated Channel
7 var channelMetadataId: String { get }
8
9 /// The current status of the MembershipMetadata
10 var status: String? { get set }
11
12 /// The current type of the MembershipMetadata
13 var type: String? { get set }
14
15 /// The associated User metadata
show all 29 lines1public protocol PubNubHashedPage {
2
3 /// The hash value representing the next set of data
4 var start: String? { get }
5
6 /// The hash value representing the previous set of data
7 var end: String? { get }
8
9 /// The total count of all objects withing range
10 var totalCount: Int? { get }
11}
Failure
An Error describing the failure.
Sample code
1
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:
1func removeMemberships(
2 userId metadataId: String?,
3 channels memberships: [PubNubMembershipMetadata],
4 include: PubNub.MembershipInclude = PubNub.MembershipInclude(),
5 filter: String? = nil,
6 sort: [PubNub.MembershipSortField] = [],
7 limit: Int? = 100,
8 page: PubNubHashedPage? = Page(),
9 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
10 completion: ((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)?
11)
| Parameter | Description |
|---|---|
userId *Type: String Default: 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. |
includeType: PubNub.MembershipIncludeDefault: PubNub.MembershipInclude() | Whether to include additional fields. |
filterType: 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. |
sortType: [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. |
limitType: Int? Default: 100 | The number of objects to retrieve at a time. |
pageType: PubNubHashedPage? Default: PubNub.Page() | The paging object used for pagination. |
customDefault: PubNub.RequestConfiguration() | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section. |
completionType: ((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).
1public protocol PubNubMembershipMetadata {
2
3 /// The unique identifier of the associated User
4 var userMetadataId: String { get }
5
6 /// The unique identifier of the associated Channel
7 var channelMetadataId: String { get }
8
9 /// The current status of the MembershipMetadata
10 var status: String? { get set }
11
12 /// The current type of the MembershipMetadata
13 var type: String? { get set }
14
15 /// The associated User metadata
show all 29 lines1public protocol PubNubHashedPage {
2
3 /// The hash value representing the next set of data
4 var start: String? { get }
5
6 /// The hash value representing the previous set of data
7 var end: String? { get }
8
9 /// The total count of all objects withing range
10 var totalCount: Int? { get }
11}
Failure
An Error describing the failure.
Sample code
1
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:
1func fetchMembers(
2 channel: String?,
3 include: PubNub.MemberInclude = PubNub.MemberInclude(),
4 filter: String? = nil,
5 sort: [PubNub.MembershipSortField] = [],
6 limit: Int? = 100,
7 page: PubNubHashedPage? = Page(),
8 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
9 completion: ((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)?
10)
| Parameter | Description |
|---|---|
channel *Type: String Default: n/a | Unique Channel Metadata identifier. |
includeType: PubNub.MemberIncludeDefault: PubNub.MemberInclude() | Whether to include additional fields. |
filterType: 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. |
sortType: [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. |
limitType: Int? Default: 100 | The number of objects to retrieve at a time. |
pageType: PubNubHashedPage? Default: PubNub.Page() | The paging object used for pagination. |
customDefault: PubNub.RequestConfiguration() | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section. |
completionType: ((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 |
|---|---|
customFieldsType: BoolDefault: true | Whether to include the custom dictionary for the membership object |
uuidFieldsType: BoolDefault: false | Whether to include the full PubNubUserMetadata instance in the membership |
statusFieldType: BoolDefault: true | Whether to include the status field of the membership object |
typeFieldType: BoolDefault: true | Whether to include the type field of the membership object |
uuidTypeFieldType: BoolDefault: false | Whether to include the type field of the associated user metadata |
uuidStatusFieldType: BoolDefault: false | Whether to include the status field of the associated user metadata |
uuidCustomFieldsType: BoolDefault: false | Whether to include the custom dictionary of the associated user metadata |
totalCountType: BoolDefault: 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).
1public protocol PubNubMembershipMetadata {
2
3 /// The unique identifier of the associated User
4 var userMetadataId: String { get }
5
6 /// The unique identifier of the associated Channel
7 var channelMetadataId: String { get }
8
9 /// The current status of the MembershipMetadata
10 var status: String? { get set }
11
12 /// The current type of the MembershipMetadata
13 var type: String? { get set }
14
15 /// The associated User metadata
show all 29 lines1public protocol PubNubHashedPage {
2
3 /// The hash value representing the next set of data
4 var start: String? { get }
5
6 /// The hash value representing the previous set of data
7 var end: String? { get }
8
9 /// The total count of all objects withing range
10 var totalCount: Int? { get }
11}
Failure
An Error describing the failure.
Sample code
1
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:
1func setMembers(
2 channel metadataId: String,
3 users members: [PubNubMembershipMetadata],
4 include: PubNub.MemberInclude = PubNub.MemberInclude(),
5 filter: String? = nil,
6 sort: [PubNub.MembershipSortField] = [],
7 limit: Int? = 100,
8 page: PubNubHashedPage? = Page(),
9 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
10 completion: ((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)?
11)
| Parameter | Description |
|---|---|
channel *Type: String Default: n/a | Unique Channel identifier. |
users *Type: [PubNubMembershipMetadata] Default: n/a | Array of PubNubMembershipMetadata with the PubNubUserMetadata or userMetadataId provided. |
includeType: PubNub.MemberIncludeDefault: PubNub.MemberInclude() | Whether to include additional fields. |
filterType: 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. |
sortType: [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. |
limitType: Int? Default: 100 | The number of objects to retrieve at a time. |
pageType: PubNubHashedPage? Default: PubNub.Page() | The paging object used for pagination. |
customDefault: PubNub.RequestConfiguration() | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section. |
completionType: ((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)?Default: nil | The async Result of the method call. |
API limits
To learn about the maximum length of parameters used to set channel members metadata, refer to REST API docs.
Completion handler result
Success
A Tuple containing an Array of PubNubMembershipMetadata, and the next pagination PubNubHashedPage (if one exists).
1public protocol PubNubMembershipMetadata {
2
3 /// The unique identifier of the associated User
4 var userdMetadataId: String { get }
5
6 /// The unique identifier of the associated Channel
7 var channelMetadataId: String { get }
8
9 /// The current status of the MembershipMetadata
10 var status: String? { get set }
11
12 /// The current type of the MembershipMetadata
13 var type: String? { get set }
14
15 /// The associated User metadata
show all 29 lines1public protocol PubNubHashedPage {
2
3 /// The hash value representing the next set of data
4 var start: String? { get }
5
6 /// The hash value representing the previous set of data
7 var end: String? { get }
8
9 /// The total count of all objects withing range
10 var totalCount: Int? { get }
11}
Failure
An Error describing the failure.
Sample code
1
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:
1func removeMembers(
2 channel metadataId: String,
3 users members: [PubNubMembershipMetadata],
4 include: PubNub.MemberInclude = PubNub.MemberInclude(),
5 filter: String? = nil,
6 sort: [PubNub.MembershipSortField] = [],
7 limit: Int? = 100,
8 page: PubNubHashedPage? = Page(),
9 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
10 completion: ((Result<(memberships: [PubNubMembershipMetadata], next: PubNubHashedPageBase?), Error>) -> Void)?
11)
| Parameter | Description |
|---|---|
channel *Type: String Default: n/a | Unique Channel identifier. |
uuids *Type: [PubNubMembershipMetadata] Default: n/a | Array of PubNubMembershipMetadata with the PubNubUserMetadata or userMetadataId provided. |
includeType: PubNub.MemberIncludeDefault: PubNub.MemberInclude() | Whether to include additional fields. |
filterType: 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. |
sortType: [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. |
limitType: Int? Default: 100 | The number of objects to retrieve at a time. |
pageType: PubNubHashedPage? Default: PubNub.Page() | The paging object used for pagination. |
customDefault: PubNub.RequestConfiguration() | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section. |
completionType: ((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).
1public protocol PubNubMembershipMetadata {
2
3 /// The unique identifier of the associated User
4 var userdMetadataId: String { get }
5
6 /// The unique identifier of the associated Channel
7 var channelMetadataId: String { get }
8
9 /// The current status of the MembershipMetadata
10 var status: String? { get set }
11
12 /// The current type of the MembershipMetadata
13 var type: String? { get set }
14
15 /// The associated User metadata
show all 29 lines1public protocol PubNubHashedPage {
2
3 /// The hash value representing the next set of data
4 var start: String? { get }
5
6 /// The hash value representing the previous set of data
7 var end: String? { get }
8
9 /// The total count of all objects withing range
10 var totalCount: Int? { get }
11}
Failure
An Error describing the failure.
Sample code
1