//
//  ViewController.swift
//  CounterNavigation
//
//  Created by Bermotech on 17/07/2018.
//  Copyright © 2018 Bermotech. All rights reserved.
//

import UIKit

class ViewController: UIViewController
{
    
    var timer = Timer()
    var counter = 0

    @IBOutlet weak var myCounter: UILabel!
    override func viewDidLoad()
    {
        super.viewDidLoad()
        myCounter.text = String(counter)
    }
    
    @IBAction func start(_ sender: Any)
    {
        timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(update), userInfo: nil, repeats: true)
        
    }
    @objc func  update()
    {
        counter+=1
        myCounter.text = String(counter)
        if counter == 5
        {
            let sboard = UIStoryboard(name: "Main", bundle: nil)
            
            let vc2: AnyObject! = sboard.instantiateViewController(withIdentifier: "SecondViewController")
            
            self.show(vc2 as! UIViewController, sender: self)
            
        }
    }

    override func didReceiveMemoryWarning()
    {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

