I have a variable that I fill like this:
var animation = [String: Void]()
animation["a"] = animationA()
But executing my code automatically executes the function animationA()
, something I want to avoid, since what I want is that when I call the variable like this: animation["a"]()
, then it is executed.
And if I place the variable in the array as follows, animation["a"] = animationA
it throws me an error.
Does anyone know if this can be done so that my function remains in a variable of an array?
Greetings and thanks in advance.
update 1
For an array I could do it, but not yet for a dictionary:
//Así lo declaro
var array: [(Void -> Void)] = []
//Aquí asigno la función
array.append { () -> () in
self.animationDefault()
}
//Así ejecuto la función
array[0]()
After trying a thousand ways, I was able to do it like this: