//
//  ViewController.swift
//  8. Timer
//
//  Created by Bermotech on 11/05/2018.
//  Copyright © 2018 App for Apple. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    
    var timer = Timer()
    var counter = 0
    var running = false
    
    @IBOutlet weak var myCounter: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        myCounter.text = String(counter)
        
    }

    @IBAction func reset(_ sender: Any) {
        timer.invalidate()
        running = false
        counter = 0
        myCounter.text = String(counter)
    }
    
    @IBAction func pause(_ sender: Any) {
        timer.invalidate()
        running = false
    }
    
    @objc func  update()
    {
        counter+=1
        myCounter.text = String(counter)
    }
   
        @IBAction func start(_ sender: Any) {
        if !running
            
        {   timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(update), userInfo: nil, repeats: true)
            running = true
        }
    }
   
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

