I try to write an animation with Swift 5, following are some codes
let animations:(() -> Void) = {
self.keyboardOPT.transform = CGAffineTransform(translationX: 0,y: -deltaY)
if duration > 0 {
let options = UIView.AnimationOptions(rawValue: UInt((userInfo[UIResponder.keyboardAnimationCurveUserInfoKey] as! NSNumber).intValue << 16))
UIView.animate(withDuration: duration, delay: 0, options: options, animations: animations, completion: nil)
} else {
animations()
}
}
But in animations: animations and animations() it shows error:
Variable used within its own initial value
animations=>let animations:.... Inside this block, in yourelsestatement, you also callanimations(). So your calling the block inside the block. You cannot do this.