How to create dispatch queue in Swift 3

前端 未结 15 1880
余生分开走
余生分开走 2020-11-22 16:35

In Swift 2, I was able to create queue with the following code:

let concurrentQueue = dispatch_queue_create(\"com.swift3.imageQueue\", DISPATCH_QUEUE_CONCURR         


        
相关标签:
15条回答
  • 2020-11-22 17:17
     DispatchQueue.main.async {
              self.collectionView?.reloadData() // Depends if you were populating a collection view or table view
        }
    
    
    OperationQueue.main.addOperation {
        self.lblGenre.text = self.movGenre
    }
    

    //use Operation Queue if you need to populate the objects(labels, imageview, textview) on your viewcontroller

    0 讨论(0)
  • 2020-11-22 17:19
     let newQueue = DispatchQueue(label: "newname")
     newQueue.sync { 
    
     // your code
    
     }
    
    0 讨论(0)
  • 2020-11-22 17:20
    DispatchQueue.main.async(execute: {
       // code
    })
    
    0 讨论(0)
  • 2020-11-22 17:21

    For Swift 3

       DispatchQueue.main.async {
            // Write your code here
        }
    
    0 讨论(0)
  • 2020-11-22 17:22

    Swift 3

    you want call some closure in swift code then you want to change in storyboard ya any type off change belong to view your application will crash

    but you want to use dispatch method your application will not crash

    async method

    DispatchQueue.main.async 
    {
     //Write code here                                   
    
    }
    

    sync method

    DispatchQueue.main.sync 
    {
         //Write code here                                  
    
    }
    
    0 讨论(0)
  • 2020-11-22 17:22

    it is now simply:

    let serialQueue = DispatchQueue(label: "my serial queue")
    

    the default is serial, to get concurrent, you use the optional attributes argument .concurrent

    0 讨论(0)
提交回复
热议问题