user2688045
user2688045

Reputation:

Variable used within its own initial value in Swift 5

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

Upvotes: 0

Views: 1020

Answers (1)

Mushrankhan
Mushrankhan

Reputation: 803

You can not call itself when initializing. You can achieve it like this also.

var animations:(() -> Void)!

animations = {
    animations()
}

Upvotes: 1

Related Questions