==> swift 3 version in perfect work but swift 4 and swift 4.2 in now working.
static func animate(_ duration: TimeInterval,
animations: (() -> Void)!,
delay: TimeInterval = 0,
options: UIViewAnimationOptions = [],
withComplection completion: (() -> Void)! = {}) {
UIView.animate(
withDuration: duration,
delay: delay,
options: options,
animations: {
animations()
}, completion: { finished in
completion()
})
}
static func animateWithRepeatition(_ duration: TimeInterval,
animations: (() -> Void)!,
delay: TimeInterval = 0,
options: UIViewAnimationOptions = [],
withComplection completion: (() -> Void)! = {}) {
var optionsWithRepeatition = options
optionsWithRepeatition.insert([.autoreverse, .repeat])
self.animate(
duration,
animations: {
animations()
},
delay: delay,
options: optionsWithRepeatition,
withComplection: { finished in
completion()
})
}
Error display on xcode =>
Cannot convert value of type '(_) -> Void' to expected argument type '(() -> Void)?'
You declared the
animatefunction such that itscompletionparameter takes no input arguments. However, you are trying to call an input argument,finishedin your closure when you call that function inanimateWithRepetition. Just removefinishedand your code compiles fine.P.S.: I've corrected the typos in your input argument names. Passing in an input argument of implicitly unwrapped type also doesn't make much sense. Either make
animationsa normalOptionaland safely unwrap it or rather make it non-Optionalif it should never benil.