---
source_url: https://www.pubnub.com/docs/chat/community-supported/ios/chat-provider
title: Chat Provider for PubNub Chat Components for iOS
updated_at: 2026-05-20T11:04:17.633Z
---

> 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


# Chat Provider for PubNub Chat Components for iOS

`ChatProvider` is the general interface for UI and data operations across the component library with many objects implemented as [Generics](https://docs.swift.org/swift-book/LanguageGuide/Generics.html). `ChatProvider` assures an overarching `Type` structure to coordinate the underlying data, services, themes, and view models.

## Configuration

You can configure `ChatProvider` using the following parameters.

:::note Required parameters
Required parameters don't have default values. If a parameter has a default value, it's optional.
:::

| Parameter | Default value | Description |
| --- | --- | --- |
| datastoreConfiguration | DatastoreConfiguration | Optional |  | `.pubnubDefault` | Configuration used when creating or connecting to the local `CoreData` instance. |
| pubnubConfiguration | PubNubConfiguration | Optional |  | n/a | Configuration that's used to create a managed `PubNub` instance. |

## Persistent database

Chat components rely on a local `CoreData` instance to manage the flow of data to the components. Network data, also known as `Model` objects, is fetched from remote APIs and then converted to `Managed` objects for storage inside of the `CoreData` instance. Meanwhile, the UI components create local connections to the `CoreData` instance to populate their views with data. `CoreData` automatically updates the displayed data as it changes or as new data is added.

To learn more about `CoreData`, refer to the [official Apple docs](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CoreData/index.html#//apple_ref/doc/uid/TP40001075-CH2-SW1).

### Structure

Chat components are configured with a predefined [Managed Object Model](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CoreData/KeyConcepts.html) that define the `NSManagedObject` objects that implement the default `ManagedChatEntities`.

To allow for the customization of data, the default `Managed` object schema can be replaced if the custom schema implements the `ManagedChatEntities` protocol.

#### Managed vs Model objects

The following table describes the relationships between the `Managed` and `Model` objects:

| Default Managed object | ManagedChatEntities protocol | Model object | Generic custom data | Description |
| --- | --- | --- | --- | --- |
| `PubNubManagedChannel` | `ManagedChatChannel` | `ChatChannel` | `ChannelCustomData` | Channel data objects |
| `PubNubManagedUser` | `ManagedChatUser` | `ChatUser` | `UserCustomData` | User data objects |
| `PubNubManagedMember` | `ManagedChatMember` | `ChatMember` | `ChatCustomData` | Relationship between channel and user data that also tracks presence. |
| `PubNubManagedMessage` | `ManagedChatMessage` | `ChatMessage` | `ChatCustomData` | Message data objects |
| `PubNubManagedMessageAction` | `ManagedChatMessageAction` | `ChatMessageAction` | `ChatCustomData` | Message reactions data objects |

### Basic example

This example creates default `ChatProvider` using the default PubNub `Type` structure.

```swift
var pubnubConfig = PubNubConfiguration(
  publishKey: "pub-c-key",
  subscribeKey: "sub-c-key",
  userId: "userId-of-current-user"
  )
  
let chatProvider = ChatProvider<VoidCustomData, PubNubManagedChatEntities>(
  pubnubConfiguration: pubnubConfig
)
```

#### Type aliases

You can use a [typealias](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#ID361) to make typing out the full `Generic` object name easier. For example, the above `ChatProvider` object has a public `typealias` of `PubNubChatProvider`, so `PubNubChatProvider` is interchangeable with any instance of `ChatProvider<VoidCustomData, PubNubManagedChatEntities>`. To do this in your code, follow the structure below:

```swift
public typealias PubNubChatProvider = ChatProvider<VoidCustomData, PubNubManagedChatEntities>
```

## Local providers

A reference to `ChatProvider` is passed to the UI components and can be used to provide more rich functionality using the following providers.

### DataProvider

Provides methods you can use to store data into the `CoreData` instance. This includes convenience methods for pagination and auto response storage of PubNub API methods and a subscription listener that stores subscribe events.

### PubNubProvider

Provides access to the `PubNub` instance used by chat components with responses conforming to `Model` data used by `ChatProvider`. Use it to make direct calls to `PubNub` APIs without storing the response. You can still store the response afterward using the corresponding `DataProvider` methods.

### ThemeProvider

Provides a template that can be used to modify the theme used by chat components. The template consists of the following themes:

* [ChannelListComponentTheme](https://www.pubnub.com/docs/chat/community-supported/ios/ui-theming#channellist)
* [MemberListComponentTheme](https://www.pubnub.com/docs/chat/community-supported/ios/ui-theming#memberlist)
* [MessageListComponentTheme](https://www.pubnub.com/docs/chat/community-supported/ios/ui-theming#messagelist)
* [MessageInputComponentTheme](https://www.pubnub.com/docs/chat/community-supported/ios/ui-theming#messageinput)