For AI agents: this page in Markdown: https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/users/create.md. Documentation index: https://www.pubnub.com/llms-full.txt.
Create users
Use createUser() to create a new User with a unique User ID.
Requires App Context
Enable App Context on your keyset in the Admin Portal to store user data.
Method signature
This method takes the following parameters:
1chat.createUser(
2 id: String,
3 name: String? = nil,
4 externalId: String? = nil,
5 profileUrl: String? = nil,
6 email: String? = nil,
7 custom: [String: JSONCodableScalar]? = nil,
8 status: String? = nil,
9 type: String? = nil
10) async throws -> UserImpl
Input
required
idrequired#name#- Display name for the user (must not be empty or consist only of whitespace characters).
externalId#- User's identifier in an external system. You can use it to match
idwith a similar identifier from an external database. profileUrl#- URL of the user's profile picture.
email#- User's email address.
custom#- JSON providing custom data about the user. Values must be scalar only; arrays or objects are not supported. Filtering App Context data through the
customproperty is not recommended in SDKs. status#- Tag that lets you categorize your app users by their current state. The tag choice is entirely up to you and depends on your use case. For example, you can use
statusto mark users in your chat app asinvited,active, orarchived. type#- Tag that lets you categorize your app users by their functional roles. The tag choice is entirely up to you and depends on your use case. For example, you can use
typeto group users by their roles in your app, such asmoderator,player, orsupport-agent.
API limits
To learn about the maximum length of parameters used to set user metadata, refer to REST API docs.
Output
UserImpl#UserImplcontaining the newly created user object.
Sample code
Sample code
The code samples in Swift Chat SDK focus on asynchronous code execution.
You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.
Create a user with an ID of support_agent_15. Specify their name, avatar, and custom attributes, such as their title and the LinkedIn profile URL.
1