So I have my first closure here:
var instructions: (() -> Void) = {
print("First")
}
instructions() /// prints "First"
Now I have another closure:
let additionalInstructions: (() -> Void) = {
print("Second")
}
additionalInstructions() /// prints "Second"
I want to "append" additionalInstructions to the end of instructions... is this possible? I tried making a new closure containing both of them, like this:
let finalInstructions: (() -> Void) = {
instructions()
additionalInstructions()
}
finalInstructions()
This prints
First
Second
But, when I replace instructions with finalInstructions, I get an EXC_BAD_ACCESS.
instructions = finalInstructions
instructions() /// error here
I think this is because closures are reference types, and some sort of loop happens when instructions contains itself. Is there a way to avoid the error? Making a new closure like finalInstructions, just as a container, also seems kind of clunky.
