Last active
December 17, 2017 19:26
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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