> For the complete documentation index, see [llms.txt](https://docs.abtasty.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.abtasty.com/server-side/integrations/open-feature/open-feature-js-1/open-feature-js-quick-start.md).

# Quick-start

### Installation

Refer to the [installation](/server-side/integrations/open-feature/open-feature-js-1/open-feature-js-installation.md) page for installation steps.

### Getting started

Below is a simple example that describes the instantiation of the ABTasty Provider. Please see the [OpenFeature Documentation](https://docs.openfeature.dev/docs/reference/concepts/evaluation-api) for details on how to use the OpenFeature SDK.

#### Add the following to your Package.swift:

```swift
dependencies: [
    .package(url: "https://github.com/flagship-io/openfeature-provider-iOS.git", from: "1.0.0")
]
```

Import the required modules:

```swift
import ABTastyOpenfeature_iOS
import OpenFeature
```

#### Register the ABTastyProvider with OpenFeature

`Init` and `Set` provider with `context`

{% hint style="info" %}
In the context use the **targetingKey** for the visitorId and you should mention **hasConsented through the context**
{% endhint %}

```swift
 
 // Create a context with an "openUserId"
 let ctx = MutableContext(
            targetingKey: "openUserId",
            structure: MutableStructure(attributes: ["isQA": Value.boolean(true),
                                                     "city": Value.string("FR"),
                                                     "hasConsented": Value.boolean(true),
                                                     "ctx1": Value.boolean(false),
                                                     "ctx2": Value.integer(125),
                                                     "ctx3": Value.double(12.0)])
                                                     
Task {
    // Create ABTasty provider
   let provider = ABTastyProvider(envId: "envId", apiKey: "apiKey", configurator: FSConfigBuilder().build())
   // Set provider through OpenFeature API
   await OpenFeatureAPI.shared.setProviderAndWait(provider: provider, initialContext: ctx)
}
```

### Flag Evaluation (Read Flag)

After `init` and `set` provider with the apropriate `context` use the client instance to get the evaluation flag

```swift
// Update UIs on the main thread
DispatchQueue.main.async {
 // get a bool flag value
 let client = OpenFeatureAPI.shared.getClient()
 // Retreive the String flag for 'btnTitle'key
 let btnTitle = client.getStringValue(key: "btnTitle", defaultValue: "default")
 // Retreive the Integer flag for 'intValue'key
 let intValue = client.getIntegerValue(key: "intValue", defaultValue: 0)
 // Update UIs
}
```

### Context Updates

On visitor context changed use `setEvaluationContextAndWait` function before read flag value

```swift
 // New context to inject 
  let updatedContext = MutableContext(
            targetingKey: "openUserId",
            structure: MutableStructure(attributes: ["isQA": Value.boolean(false)]))
  Task {
        await OpenFeatureAPI.shared.setEvaluationContextAndWait(evaluationContext: updatedContext)
        // Refresh the values after context update
            DispatchQueue.main.async {
                let client = OpenFeatureAPI.shared.getClient()
                // get String value for 'btnTitle' key flag
                let btnTitle = client.getStringValue(key: "btnTitle", defaultValue: "default")
                // get Integer value for 'intValue' key flag
                let intValue = client.getIntegerValue(key: "intValue", defaultValue: 0)
                // Update UIs
        }
    }

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.abtasty.com/server-side/integrations/open-feature/open-feature-js-1/open-feature-js-quick-start.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
