Feature Flag Determination

📘

Feature flags are only available for SDK version 2.0.0 or higher.

When using feature flags, please apply SDK version 2.0.0 or higher when adding dependencies.

A feature flag has an on and off state. You will set different features according to each state.

Once a feature flag is applied, a specific user from your traffic should be able to either receive an on or off status. This on/off status determination can be done through the Hackle SDK.

isFeatureOn

You can pass a feature key to the isFeatureOn() method to receive status results for the user. After receiving the status, we can then implement the logic according to each status.

In the example code below, we are passing feature key 42.

// Determines the status of the feature flag to assign the user in a feature flag with a feature key of 42.
// For undetermined cases, users are assigned to false (off status). 
let isFeatureOn: Bool = hackleApp.isFeatureOn(featureKey: 42)

if isFeatureOn {
    // Logic for on status
} else {
    // Logic for off status
}
// Determines the status of the feature flag to assign the user in a feature flag with a feature key of 42.
// For undetermined cases, users are assigned to false (off status). 
bool isFeatureOn = [hackleApp isFeatureOnFeatureKey:@42];

if (isFeatureOn) {
    // Logic for on status
} else {
    // Logic for off status
}

featureFlagDetail

The featureFlagDetail() method works the same as the isFeatureOn() method and additionally provides a reason for determining the status of a particular user. This can be useful when you want to check whether the manual allocation is working well or when you think that the traffic allocation you have set is not being reflected in your results.

You must pass a function key as a parameter. For the example code below, we are passing function key 42.

// Status determination details
let decision: FeatureFlagDecision = hackleApp.featureFlagDetail(featureKey: 42)

// Feature flag on/off results 
let isFeatureOn: Bool = decision.isOn

// Reason for status determination
let reason: String = decision.reason
// Status determination details
FeatureFlagDecision *decision = [hackleApp featureFlagDetailWithFeatureKey:@42];

// Feature flag on/off results 
bool isFeatureOn = [decision isOn];

// Reason for status determination
NSString *reason = [decision reason];

The reason for the status determination will be in the form of SDK_NOT_READY. Please refer to the table below for the full list of all the different types of reasons.

ReasonDescriptionFeature Status
SDK_NOT_READYThe SDK is not ready to use.
(e.g. trying to initialize with the wrong SDK key)
Default status(off)
FEATURE_FLAG_NOT_FOUNDNo feature flags were found for the function key you passed in.
The feature key may be incorrect or the corresponding feature flag may be in an archived state.
Default status(off)
FEATURE_FLAG_INACTIVEThe feature flag is off.Default status(off)
INDIVIDUAL_TARGET_MATCHUser has been matched to individual targeting settings.Set to individual targeting
TARGET_RULE_MATCHUser has been matched to audience targeting settings.Set to audience targeting
DEFAULT_RULEUser has not been matched to either individual targeting or audience targeting.Default status (off)
EXCEPTIONAn unknown error has occurred.Default status(off)

Feature Flag Parameter

  • Call featureFlagDetail() method to obtain parameter values which contains the feature flag status information
  • FeatureFlagDecisioninstance passed through the featureFlagDetail() method has full parameter setting information.
  • Parameter values you've set on the dashboard exists in the form of key and value, therefore you can use the method below to set the parameter values.
  • You can change feature flag's parameter values flexibly on the Feature Flag > Parameter Settings.

📘

Parameter setting is only available for SDK version 2.9.0 or higher.

getString

  • Returns the parameter value set to STRING, JSON type.
  • Returns the default value or the value set in the rule based on the status determination.
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")
FeatureFlagDecision *decision = [[Hackle app] featureFlagDetailWithFeatureKey:@42];

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

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

getInt

  • Returns the parameter value set to Number type as Int type.
  • Returns the default value or the value set in the rule based on the status determination.
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)
FeatureFlagDecision *decision = [[Hackle app] featureFlagDetailWithFeatureKey:@42];

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

getDouble

  • Returns the parameter value set to Number type as Double type.
  • Returns the default value or the value set in the rule based on the status determination.
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)
FeatureFlagDecision *decision = [[Hackle app] featureFlagDetailWithFeatureKey:@42];

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

getBool

  • Returns the parameter value set to Boolean type.
  • Returns the default value or the value set in the rule based on the status determination.
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)
FeatureFlagDecision *decision = [[Hackle app] featureFlagDetailWithFeatureKey:@42];

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