# Conditional Feature Flags

{% hint style="info" %}
Be sure to read our [Feature Flag Guide](https://docs.criticalmoments.io/guides/feature-flags-guide), which covers common Feature Flag implementations.
{% endhint %}

[Feature flags](https://www.martinfowler.com/articles/feature-toggles.html) are great way to enable new features, stage rollouts, and disable features that are end of life.&#x20;

However, static flags and randomized rollout often aren't powerful enough. What happens if you find out your new feature has a bug on iPad, issues on cellular networks, or bugs in some locales? What if you want to target only long standing users initially to prevent data from new users clouding the results of AB test?

You can't think of every condition you might need ahead of time, but with our conditional checks you can used advanced targeting, and update your targeting after you ship.

### checkNamedCondition API

This API is simple, but powerful. It evaluates a condition string, and returns if it's true or false.&#x20;

The condition strings are defined in your [config file](https://docs.criticalmoments.io/feature-flags/named-conditions-config), allowing you to update them remotely without app updates.

{% hint style="info" %}
Be sure to provide a unique name to each use case. Don't reuse names even if the current conditional logic is equivalent; that will make it impossible to override each usage independently from your remote config file.
{% endhint %}

{% tabs %}
{% tab title="Swift API" %}

```swift
// Optionally try/catch the for errors
let result = try? await CriticalMoments.shared().checkNamedCondition("userNotDistracted")
if result {
   // Perform action
}
```

{% endtab %}

{% tab title="Objective C API" %}

```objectivec
[CriticalMoments.sharedInstance 
        checkNamedCondition:@"userNotDistracted" 
        handler:^(_Bool result, NSError * _Nullable error) {
    if (error != nil) {
        NSLog(@"Error: %@", error);
    } else if (result) {
        // Perform action
    }
}];
```

{% endtab %}
{% endtabs %}

#### Parameters and Return Value

* `name`: A name for this condition. Must be provided and can not be an empty string. This name is used to look up the conditional string from your [config file's named conditions](https://docs.criticalmoments.io/feature-flags/named-conditions-config).
* `error`: Any errors returned from evaluating the condition.

#### Return Value

Returns the result of evaluating the condition. Always false for any error.

### Remote updates

You can update your conditions anytime from the cloud. The config file format to do so is described [here](https://docs.criticalmoments.io/feature-flags/named-conditions-config).&#x20;

### Advanced Usage

See our [feature flag guide](https://docs.criticalmoments.io/guides/feature-flags-guide) for tips on how to implement staged rollouts, rollback, and other feature flag strategies.


---

# Agent Instructions: 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:

```
GET https://docs.criticalmoments.io/feature-flags/conditional-feature-flags.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
