# Feature Flag Decision

{% hint style="info" %}
This feature is supported in iOS SDK 2.0.0 and above.
{% endhint %}

A Feature Flag has two states: on and off. Different features are configured for each state. When a user accesses a feature with a Feature Flag applied, the SDK must return the on or off state. You can use the Hackle SDK to make this decision.

## isFeatureOn

Pass the **Feature Key** to the `isFeatureOn()` method to receive the state result for the user. Then implement logic based on the state.

The example code below passes Feature Key 42.

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

```swift
// 기능 키가 42인 기능 플래그에서 사용자의 상태를 결정합니다.
// 결정하지 못하는 상황인 경우 false(꺼짐 상태)를 반환합니다.
let isFeatureOn: Bool = hackleApp.isFeatureOn(featureKey: 42)

if isFeatureOn {
    // ON 기능
} else {
    // OFF 기능
}
```

{% endtab %}

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

```objectivec
// 기능 키가 42인 기능 플래그에서 사용자의 상태를 결정합니다.
// 결정하지 못하는 상황인 경우 false(꺼짐 상태)를 반환합니다.
bool isFeatureOn = [hackleApp isFeatureOnFeatureKey:@42];

if (isFeatureOn) {
    // ON 기능
} else {
    // OFF 기능
}
```

{% endtab %}
{% endtabs %}

## featureFlagDetail

The `featureFlagDetail()` method works the same as `isFeatureOn()` but also provides the reason for the state decision. This is useful for checking whether an Override is working correctly, or when the distribution result seems inconsistent with the configured Traffic Allocation.

You must pass the Feature Key as a parameter. The example code below passes Feature Key 42.

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

```swift
// 상태 결정 상세
let decision: FeatureFlagDecision = hackleApp.featureFlagDetail(featureKey: 42)

// 기능 on/off 여부
let isFeatureOn: Bool = decision.isOn

// 상태 결정 사유
let reason: String = decision.reason
```

{% endtab %}

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

```objectivec
// 상태 결정 상세
HackleFeatureFlagDecision *decision = [hackleApp featureFlagDetailWithFeatureKey:@42];

// 기능 on/off 여부
bool isFeatureOn = [decision isOn];

// 상태 결정 사유
NSString *reason = [decision reason];
```

{% endtab %}
{% endtabs %}

The state decision reason is returned in the format **`SDK_NOT_READY`**. See the table below for details.

<table><thead><tr><th width="233.71875">Decision Reason</th><th width="370.8046875">Description</th><th>Distribution Result</th></tr></thead><tbody><tr><td><code>SDK_NOT_READY</code></td><td>The SDK is not ready to use.<br>(e.g., initialization attempted with an invalid SDK Key)</td><td>Default state<br>(off)</td></tr><tr><td><code>FEATURE_FLAG_NOT_FOUND</code></td><td>No Feature Flag was found for the provided Feature Key.<br>The Feature Key may be incorrect, or the Feature Flag may be archived.</td><td>Default state<br>(off)</td></tr><tr><td><code>FEATURE_FLAG_INACTIVE</code></td><td>The Feature Flag is in the off state.</td><td>Default state<br>(off)</td></tr><tr><td><code>INDIVIDUAL_TARGET_MATCH</code></td><td>Matched by Individual Targeting.</td><td>State configured by<br>Individual Targeting</td></tr><tr><td><code>TARGET_RULE_MATCH</code></td><td>Matched by User Targeting.</td><td>State configured by User Targeting</td></tr><tr><td><code>DEFAULT_RULE</code></td><td>Did not match either Individual Targeting or User Targeting.</td><td>State configured by<br>default rule</td></tr><tr><td><code>EXCEPTION</code></td><td>An unknown error occurred.</td><td>Default state<br>(off)</td></tr></tbody></table>

## Feature Flag Parameters

{% hint style="info" %}
This feature is supported in iOS SDK 2.9.0 and above.
{% endhint %}

* The `featureFlagDetail()` method also returns the parameter values for the state decision.
* The `FeatureFlagDecision` instance returned by `featureFlagDetail()` contains a `ParameterConfig` object with all parameter configuration.
* Since parameters set on the Hackle Feature Flag screen exist as key-value pairs, you can use the methods below to retrieve parameter values according to the configured parameter type.
* You can dynamically change values on the Feature Flag parameter settings screen.

### getString

* Returns a parameter value configured as STRING or JSON type.
* Returns the value configured for False or True based on the state decision.

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

```swift
let decision: FeatureFlagDecision = hackleApp.featureFlagDetail(featureKey: 42)
let config: ParameterConfig = decision.config

let strValue: String = decision.getString(forKey: "parameter_key_string_type", defaultValue: "defaultValue")
let strValueInConfig: String = config.getString(forKey: "parameter_key_string_type", defaultValue: "defaultValue")

let jsonValue: String = decision.getString(forKey: "parameter_key_json_type", defaultValue: "defaultValue")
let jsonValueInConfig: String = config.getString(forKey: "parameter_key_json_type", defaultValue: "defaultValue")
```

{% endtab %}

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

```objectivec
HackleFeatureFlagDecision *decision = [[Hackle app] featureFlagDetailWithFeatureKey:@42];

NSString *stringValue = [decision getStringForKey:@"string" defaultValue:@"defaultValue"];

NSString *jsonValue = [decision getStringForKey:@"parameter_key_json_type" defaultValue:@"defaultValue"];
```

{% endtab %}
{% endtabs %}

### getInt

* Returns a parameter value configured as Number type as an Int.
* Returns the value configured for False or True based on the state decision.

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

```swift
let decision: FeatureFlagDecision = hackleApp.featureFlagDetail(featureKey: 42)
let config: ParameterConfig = decision.config

let intValue: Int = decision.getInt(forKey: "parameter_key_number_type", defaultValue: 0)
let intValueInConfig: Int = config.getInt(forKey: "parameter_key_number_type", defaultValue: 0)
```

{% endtab %}

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

```objectivec
HackleFeatureFlagDecision *decision = [[Hackle app] featureFlagDetailWithFeatureKey:@42];

int intValue = [decision getIntForKey:@"parameter_key_number_type" defaultValue:@0];
```

{% endtab %}
{% endtabs %}

### getDouble

* Returns a parameter value configured as Number type as a Double.
* Returns the value configured for False or True based on the state decision.

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

```swift
let decision: FeatureFlagDecision = hackleApp.featureFlagDetail(featureKey: 42)
let config: ParameterConfig = decision.config

let doubleValue: Double = decision.getDouble(forKey: "parameter_key_number_type", defaultValue: 0.0)
let doubleValueInConfig: Double = config.getDouble(forKey: "parameter_key_number_type", defaultValue: 0.0)
```

{% endtab %}

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

```objectivec
HackleFeatureFlagDecision *decision = [[Hackle app] featureFlagDetailWithFeatureKey:@42];

double doubleValue = [decision getDoubleForKey:@"parameter_key_number_type" defaultValue:0.0];
```

{% endtab %}
{% endtabs %}

### getBool

* Returns a parameter value configured as Bool type.
* Returns the value configured for False or True based on the state decision.

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

```swift
let decision: FeatureFlagDecision = hackleApp.featureFlagDetail(featureKey: 42)
let config: ParameterConfig = decision.config

let boolValue: Bool = decision.getBool(forKey: "parameter_key_boolean_type", defaultValue: false)
let boolValueInConfig: Bool = config.getBool(forKey: "parameter_key_boolean_type", defaultValue: false)
```

{% endtab %}

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

```objectivec
HackleFeatureFlagDecision *decision = [[Hackle app] featureFlagDetailWithFeatureKey:@42];

bool boolValue = [decision getBoolForKey:@"parameter_key_boolean_type" defaultValue:false];
```

{% endtab %}
{% endtabs %}


---

# 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.hackle.io/en/development-guide/ios/ios-feature-flag.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.
