On this page

Delete users

Remove users with delete() or deleteUser(). Choose between permanent deletion or soft delete (preserving data in App Context storage).

  • delete() - call on a User object (no ID needed)
  • deleteUser() - call on a Chat object (requires user ID)
Requires App Context

Enable App Context in the Admin Portal to store user data.

Method signature

These methods take the following parameters:

  • delete() (on the User object)

    1user.delete(
    2 soft: Bool = false
    3) async throws -> UserImpl?
  • deleteUser() (on the Chat object)

    1chat.deleteUser(
    2 id: String,
    3 soft: Bool = false
    4) async throws -> UserImpl?

Input

ParameterRequired in delete()Required in deleteUser()Description
id
Type: String
Default:
n/a
No
Yes
Unique user identifier (up to 92 UTF-8 characters).
soft
Type: Bool
Default:
false
No
No
Define if you want to permanently remove user metadata. The user metadata gets permanently deleted from the App Context storage by default. If you set this parameter to true, the User object gets the deleted status, and you can still restore/get their metadata.

Output

ParameterDescription
UserImpl
For hard delete, the method returns nil. For soft delete, an updated user instance with the status field set to deleted.

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.

Permanently delete user support_agent_15.

  • delete()

    1
    
  • deleteUser()

    1
    

Other examples

Archive (soft delete) the user with an ID of support_agent_15, keeping their data in the App Context storage.

  • delete()

    1
    
  • deleteUser()

    1
    
Last updated on