# Hidden Pre-Chat for iOS

Use hidden pre-chat fields to capture valuable information without asking the customer directly for it.

:::important
This feature requires version 1.2.0 or later of the Enhanced In-App Chat SDK.
:::

This article applies to the following implementations:

| UI SDK | Core SDK |
| :----: | :------: |
|    ✅   |     ✅    |

After you [set up pre-chat in Salesforce](https://help.salesforce.com/s/articleView?id=service.miaw_custom_prechat\_2.htm), the UI SDK automatically presents the pre-chat form to the user and passes this information to Salesforce. If you're not using the UI SDK, the [Core SDK documentation](/docs/service/messaging-in-app/guide/ios-core-sdk.md) describes how to perform this process programmatically. To use hidden pre-chat fields, use the Core SDK. If you want to use this feature with the UI SDK, use the Core SDK with your UI SDK.

This article describes the steps that you must take from your app to send any user data *not* visible in the pre-chat form. This data is also described as hidden pre-chat fields. To learn about and set up pre-chat, see [Customize Pre-Chat for Enhanced Chat](https://help.salesforce.com/s/articleView?id=service.miaw_custom_prechat\_2.htm).

After you set up hidden pre-chat fields in Salesforce, you can populate these values using the SDK.

1. Implement the [`HiddenPreChatDelegate`](https://salesforce-async-messaging.github.io/messaging-in-app-ios/documentation/smiclientcore/hiddenprechatdelegate) interface. This delegate contains the `didRequestPrechatValues` method, which the SDK calls when it needs pre-chat values.
2. Add your delegate to the SDK using the `CoreClient.preChatDelegate` property. See the [`CoreClient`](https://salesforce-async-messaging.github.io/messaging-in-app-ios/documentation/smiclientcore/coreclient) reference documentation.

```sfdocs-code {"lang":"swift", "title": "Implement hidden pre-chat delegate", "src": "" }
class HiddenPrechatDelegateImplementation: HiddenPreChatDelegate {

  func core(_ core: CoreClient!,
            conversation: Conversation!,
            didRequestPrechatValues hiddenPreChatFields: [HiddenPreChatField]!,
            completionHandler: HiddenPreChatValueCompletion!) {

    // Use the conversation object to inspect info about the conversation

    // Fill in all the hidden pre-chat fields
    for preChatField in hiddenPreChatFields {
      // preChatField.label contains the label
      // preChatField.identifier contains the conversation identifier
      // preChatField.value is where you populate the field with a value

      preChatField.value = "My hidden pre-chat value"
    }

    // Pass pre-chat fields back to SDK
    completionHandler(hiddenPreChatFields)
  }
}
```

:::note
This sample code requires the configuration object that you created when setting up the UI SDK or the Core SDK. See [Build a UI SDK App](/docs/service/messaging-in-app/guide/ios-ui-sdk.md) or [Build a Core SDK App](/docs/service/messaging-in-app/guide/ios-core-sdk.md) for more information.
:::

```sfdocs-code {"lang":"swift", "title": "Add your delegate to the core client object", "src": "" }
// Create an instance of the hidden pre-chat delegate
let myPreChatDelegate = HiddenPrechatDelegateImplementation()

// Create a core client from a config
let coreClient = CoreFactory.create(withConfig: config)

// Assign the hidden pre-chat delegate
coreClient.preChatDelegate = myPreChatDelegate
```

After you register your delegate, the SDK automatically calls your `didRequestPrechatValues` method before a conversation begins.
