Escaping closure captures non-escaping parameter 'action'

Here is my code:
Code Block swift
func animateFlipCard( _ action: (() -> Void)) {
        UIView.animate(withDuration: 0.5, delay: 0, options: [.autoreverse], animations: {
            self.cardView.transform = CGAffineTransform(scaleX: 0.001, y: 1)
            DispatchQueue.main.asyncAfter(deadline: .now() + 1) { action() }
        }, completion: {_ in
            self.cardView.transform = CGAffineTransform.identity
        })
    }

I get the error "Escaping closure captures non-escaping parameter 'action'" on lines 2 and 4. What am I doing wrong and how can I fix this?

Answered by junkpile in 617512022
Had a reply all typed out, switched tabs, switched back and it’s all gone. !@$* new forums.

You should be able to fix it by marking that action parameter as @escaping. It has to be marked as such because the parameter goes out of scope before the closure is executed.
Accepted Answer
Had a reply all typed out, switched tabs, switched back and it’s all gone. !@$* new forums.

You should be able to fix it by marking that action parameter as @escaping. It has to be marked as such because the parameter goes out of scope before the closure is executed.
Escaping closure captures non-escaping parameter 'action'
 
 
Q