I need to work with the animation and now I have such a function that rotates the view

 func rotate360Degrees(uiView : UIView , duration: CFTimeInterval = 2.0, completionDelegate: AnyObject? = nil) { let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation") rotateAnimation.fromValue = 0.0 rotateAnimation.toValue = CGFloat(M_PI * 2) rotateAnimation.duration = duration if let delegate: CAAnimationDelegate = completionDelegate as! CAAnimationDelegate? { rotateAnimation.delegate = delegate } uiView.layer.add(rotateAnimation, forKey: nil) } 

But I am new and do not quite understand how you can use completionDelegate ?

I understand that we use delegate when we need to access methods of a particular class. Then you need to inherit from the class and make the delegate

But in this example, I do not quite understand for what purpose can I use this opportunity?

  • something is not entirely clear what you are asking. in your example, the program determines whether competionDelegate is present and assign the same class rotateAnimation.delegate - Max Mikheyenko
  • @MaxMikheyenko here I have the parameter completionDelegate which I can pass, but I can not pass. If I do not pass it, then the method takes its default value to nil and of course the if let delegate: CAAnimationDelegate check fails. My question is that I understand that completionDelegate must pass a variable of type CAAnimationDelegate that the check has passed, but I don’t quite understand what will happen if I pass to CAAnimationDelegate ? Why might you need to do this? - Aleksey Timoshchenko

0