在Swift 2中,我能够用以下代码创建队列:

let concurrentQueue = dispatch_queue_create("com.swift3.imageQueue", DISPATCH_QUEUE_CONCURRENT)

但是这不能在Swift 3中编译。

在Swift 3中,首选的方式是什么?


当前回答

你可以在swift 3.0中使用这段代码创建调度队列

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

   /* or */

let delayTime = DispatchTime.now() + Double(Int64(0.5 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)                   
DispatchQueue.main.asyncAfter(deadline: delayTime)
{
  /*Write your code here*/
}

其他回答

Swift 3

   DispatchQueue.main.async {
        // Write your code here
    }
DispatchQueue.main.async(execute: {
   // code
})
   let concurrentQueue = dispatch_queue_create("com.swift3.imageQueue", DISPATCH_QUEUE_CONCURRENT) //Swift 2 version

   let concurrentQueue = DispatchQueue(label:"com.swift3.imageQueue", attributes: .concurrent) //Swift 3 version

我在Xcode 8, Swift 3中重做了你的代码,这些变化与你的Swift 2版本形成对比。

我这样做了,如果你想在不被用户注意的情况下刷新你的UI来显示新数据,比如UITableView或UIPickerView,这就特别重要。

    DispatchQueue.main.async
 {
   /*Write your thread code here*/
 }
 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
}

//使用操作队列如果你需要填充对象(标签,imageview, textview)在你的视图控制器