I built an extension to the UIButton class to do fadeOut. When I use this I get memory leak warning in the profiler. I am using Swift 4 and Xcode 9.3.
Thanks in advance for any help.
extension UIButton {
func fadeOut() {
let fadeOut = CABasicAnimation(keyPath: "opacity")
fadeOut.duration = 0.35
fadeOut.fromValue = 1
fadeOut.toValue = 0.0
fadeOut.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
fadeOut.autoreverses = false
fadeOut.repeatCount = 0
fadeOut.isRemovedOnCompletion = true
self.layer.add(fadeOut, forKey: nil)
}
}
The calling function is given below. Also please note: new, level and card are UIButtons. When I comment out button.fadeout()
in the function below the memory leak goes away as per the Xcode profiler. Hope this gives more context. If any other information is required to help analyze, I happy to provide the info.
private func menu_fadeout(){
func menu_fadeout_helper(_ button:UIButton){
button.fadeOut()
button.isHidden = true
button.isEnabled = false
}
menu_fadeout_helper(hint)
menu_fadeout_helper(new)
menu_fadeout_helper(level)
menu_fadeout_helper(card)
}