If a particular feature flag is enabled for a user, you can then fetch the required variables corresponding to that feature flag. These variables need to be first configured in VWO, and can then be fetched at your server and used to control the user's experience in your codebase.

getVariable()

// Get the variable value for the given variable key and default value
let variable1 = featureFlagObj?.getVariable(key: "feature_flag_variable1", defaultValue: "default-value1")

the getVariable() function requires two arguments, that is the 'feature_flag_variable1' in the above example, which would be the unique key corresponding to a particular "Variable", as defined under Feature Flag > Variables, and the seond one is the default-value of that variable.

Please note that the getVariable() function needs to be called on the feature flag object returned from the previous getFlag() function.

getVariable() returns the value of the specified variable :

  • For testing rules, this value will depend on which variation the user becomes part of (for testing rules).
  • For rollouts, this will return the default value of the variable.
  • For personalise rules, it will return the appropriate value of the variable depending on what you have configured in the personalise rule in the FM&E application.

getVariables()

Similar to getVariable(), but this function returns an array of objects, with the values of all variables connected to a feature flag

// Returns the value of a single variable  
let variable1 = featureFlag?.getVariable(key: "feature_flag_variable1", defaultValue: true)

// Returns an array of all relevant variables and their values for a given feature flag  
val allVariables = featureFlag.getVariables()