In this example, we will show you how to use the CreativeEditor SDK’s CreativeEngine to modify variables through the variable API. The variable API lets you set or get the contents of variables that exist in your scene.
Functions#
public func findAll() -> [String]Get all text variables currently stored in the engine.
- Returns: Return a list of variable names.
public func set(key: String, value: String) throwsSet a text variable.
key: The variable’s key.value: The text to replace the variable with.
public func get(key: String) throws -> StringGet a text variable.
key:: The variable’s key.- Returns: The text value of the variable.
public func remove(key: String) throwsDestroy a text variable.
key:: The variable’s key.
public func referencesAnyVariables(_ id: DesignBlockID) throws -> BoolChecks whether the given block references any variables. Doesn’t check the block’s children.
id:: The block to inspect.- Returns:
trueif the block references variables andfalseotherwise.
Localizing Variable Keys (CE.SDK only)#
You can show localized labels for the registered variables to your users by
adding a corresponding label property to the object stored at
i18n.<language>.variables.<key>.label in the configuration.
Otherwise, the name used in variable.setString() will be shown.

Full Code#
Here’s the full code:
// Query all variableslet variableNames = engine.variable.findAll()
// Set, get and remove a variabletry engine.variable.set(key: "name", value: "Chris")let name = try engine.variable.get(key: "name") // Christry engine.variable.remove(key: "name")
let block = try engine.block.create(.graphic)let referencesVariables = try engine.block.referencesAnyVariables(block)