title: Swift progress view completion actions
body: <p>Helllo , I am using swift. I have this code that control a progressview on my main view controller. I feed the progress view with a double var containing seconds.  Once the progressview has completed i d like to perfom some actions on the main viewcontroller. but i have no idea on where and how to implement actions.  here is my code :</p>
  
  <pre><code>class CounterProgressView: UIView {
  
      let sharedDefaults = NSUserDefaults(suiteName: "group.birkyboy.TodayExtensionSharingDefaults")
  
      private let progressLayer: CAShapeLayer = CAShapeLayer()
  
      private var progressLabel: UILabel
  
      required init(coder aDecoder: NSCoder) {
          progressLabel = UILabel()
          super.init(coder: aDecoder)
          createProgressLayer()
      }
  
      override init(frame: CGRect) {
          progressLabel = UILabel()
          super.init(frame: frame)
          createProgressLayer()
      }
  
      private func createProgressLayer() {
          let startAngle = CGFloat(M_PI_2)
          let endAngle = CGFloat(M_PI * 2 + M_PI_2)
          let centerPoint = CGPointMake(CGRectGetWidth(frame)/2 , CGRectGetHeight(frame)/2)
  
          var gradientMaskLayer = gradientMask()
          progressLayer.path = UIBezierPath(arcCenter:centerPoint, radius: CGRectGetWidth(frame)/2 - 30.0, startAngle:startAngle, endAngle:endAngle, clockwise: true).CGPath
          progressLayer.backgroundColor = UIColor.clearColor().CGColor
          progressLayer.fillColor = UIColor.clearColor().CGColor
          progressLayer.strokeColor = UIColor.blackColor().CGColor
          progressLayer.lineWidth = 25.0
          progressLayer.strokeStart = 0.0
          progressLayer.strokeEnd = 0.0
  
          gradientMaskLayer.mask = progressLayer
          layer.addSublayer(gradientMaskLayer)
      }
  
      private func gradientMask() -&gt; CAGradientLayer {
          let gradientLayer = CAGradientLayer()
          gradientLayer.frame = bounds
  
          gradientLayer.locations = [1.0, 1.0]
  
          let colorTop: AnyObject = UIColor(red: 255.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 1).CGColor
          let colorBottom: AnyObject = UIColor(red: 255.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 0).CGColor
          let arrayOfColors: [AnyObject] = [colorTop, colorBottom]
          gradientLayer.colors = arrayOfColors
  
          return gradientLayer
      }
  
  
      func hideProgressView() {
          progressLayer.strokeEnd = 0.0
          progressLayer.removeAllAnimations()
  
      }
  
      func secondsToHoursMinutesSeconds (seconds : Double) -&gt; (Double, Double, Double) {
          let (hr,  minf) = modf (seconds / 3600)
          let (min, secf) = modf (60 * minf)
          return (hr, min, 60 * secf)
      }
  
      func  animateProgressView() {
  
          progressLayer.strokeEnd = 0.0
  
          var temps = sharedDefaults!.objectForKey("roueCounter") as? Double
  
          println(temps)
          let animation = CABasicAnimation(keyPath: "strokeEnd")
          animation.fromValue = CGFloat(0.0)
          animation.toValue = CGFloat(1)
          animation.duration = temps!
          animation.delegate = self
          animation.removedOnCompletion = false
          animation.additive = true
          animation.fillMode = kCAFillModeForwards
  
          progressLayer.addAnimation(animation, forKey: "strokeEnd")
      }
  
      override func animationDidStop(anim: CAAnimation!, finished flag: Bool) {
  
      }
  }
  </code></pre>
  
  <p>And this the functions on the main viewController that call the progressview :</p>
  
  <pre><code>func secondsToHoursMinutesSeconds (seconds : Int) {
  
      sharedDefaults!.setObject(seconds, forKey: "roueCounter")
      sharedDefaults!.synchronize()
  
      let (h, m, s) = (seconds / 3600, (seconds % 3600) / 60, (seconds % 3600) % 60)
  
      if m &lt; 10 {
          counterInfosLabel.text = "FROM CURRENT TIME IN"
          counter.text = "\(h)H0\(m)"
          println ("\(h) Hours, 0\(m) Minutes")
          counterProgressView.animateProgressView()
      } else {
          counterInfosLabel.text = "FROM CURRENT TIME IN"
          counter.text = "\(h)H\(m)"
          println ("\(h) Hours, \(m) Minutes")
          counterProgressView.animateProgressView()
      }
  
      if h == 0 &amp;&amp; (m &lt;= 5 &amp;&amp; m &gt; 0){
          counter.textColor = UIColor.redColor()
          counterInfosLabel.text = "FROM CURRENT TIME IN"
          PKNotification.toastBackgroundColor = UIColor.redColor()
          PKNotification.toast("You are Illegal in 5 minutes")
          counterProgressView.animateProgressView()
  
          var localNotification = UILocalNotification()
          localNotification.fireDate = NSDate(timeIntervalSinceNow: 1)
          localNotification.alertBody = "You Are Illegal In 5 Minutes."
          localNotification.timeZone = NSTimeZone.defaultTimeZone()
          localNotification.soundName = "chime.mp3"
          localNotification.category = "CATAGORY_1"
          UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
      }
      if h &lt;= 0 &amp;&amp; m &lt;= 0 {
          counterInfosLabel.text = "ILLEGAL SINCE"
          counter.text = "\(-h)H\(-m)MN"
          PKNotification.toastBackgroundColor = UIColor.redColor()
          PKNotification.toast("You are Illegal")
  
          var localNotification = UILocalNotification()
          localNotification.fireDate = NSDate(timeIntervalSinceNow: 1)
          localNotification.alertBody = "You Are Illegal !"
          localNotification.timeZone = NSTimeZone.defaultTimeZone()
          localNotification.soundName = "chime.mp3"
          localNotification.category = "CATAGORY_1"
          UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
      }
  }
  </code></pre>
  
  <p>Thank you for any help you can provide me.</p>