dispatch_after - GCD in Swift?

前端 未结 25 2378
心在旅途
心在旅途 2020-11-21 06:07

I\'ve gone through the iBook from Apple, and couldn\'t find any definition of it:

Can someone explain the structure of dispatch_after?

d         


        
25条回答
  •  梦如初夏
    2020-11-21 06:46

    In Swift 3.0

    Dispatch queues

      DispatchQueue(label: "test").async {
            //long running Background Task
            for obj in 0...1000 {
                print("async \(obj)")
            }
    
            // UI update in main queue
            DispatchQueue.main.async(execute: { 
                print("UI update on main queue")
            })
    
        }
    
        DispatchQueue(label: "m").sync {
            //long running Background Task
            for obj in 0...1000 {
                print("sync \(obj)")
            }
    
            // UI update in main queue
            DispatchQueue.main.sync(execute: {
                print("UI update on main queue")
            })
        }
    

    Dispatch after 5 seconds

        DispatchQueue.main.after(when: DispatchTime.now() + 5) {
            print("Dispatch after 5 sec")
        }
    

提交回复
热议问题