Skip to content

QueenieCplusplus/iOS_Back_8

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

iOS_Back_8

Multi-Threads using Timer

  1. code

     //
     //  ViewController.swift
     //  KatesThreadsApp
     //
     //  Created by KatesAndroid on 2021/1/28 AM 10:15
     //  multi-threads using Timer class
    
     import UIKit
    
     class ViewController: UIViewController {
    
         override func viewDidLoad() {
             super.viewDidLoad()
    
             //Timer.scheduledTimer(timeInterval: <#T##TimeInterval#>, invocation: <#T##NSInvocation#>, repeats: <#T##Bool#>)
    
             Timer.scheduledTimer(withTimeInterval: 5.0, repeats: true){
    
                 (t) in
                 self.timeCounter()
    
             }
    
         }
    
         func timeCounter(){
             let showTime = DateFormatter()
             showTime.dateFormat = "hh:mm:ss"
             let timeString = showTime.string(from: Date())
             print(timeString)
         }
    
     }
    
  2. output

  3. iOS' tip (log)

     NSLog("")
     
     sleep()