Skip to content

Instantly share code, notes, and snippets.

@bulentsiyah
Last active December 17, 2017 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bulentsiyah/babb009160a192857ebab7a44472c3e0 to your computer and use it in GitHub Desktop.
Save bulentsiyah/babb009160a192857ebab7a44472c3e0 to your computer and use it in GitHub Desktop.
Zamanlayıcı (Timer) Örneği | Swift 4 --- http://www.bulentsiyah.com/zamanlayici-timer-ornegi-swift-4/
//
// ViewController.swift
// Timers
//
// Created by Bülent Siyah on 17.12.2017.
// Copyright © 2017 Bülent Siyah. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var timeLabel: UILabel!
var timer = Timer()
var counter=0
override func viewDidLoad() {
super.viewDidLoad()
counter=10
timeLabel.text = String(counter)
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(ViewController.timerFunction), userInfo: nil, repeats: true)
}
@objc func timerFunction(){
timeLabel.text = String(counter)
counter = counter-1
if(counter == 0){
timer.invalidate()
timeLabel.text = "Time's Off"
}
//print("timer working")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment