dispatch_queue和NSOperationQueue有什么区别?

时间:2016-03-23 12:23:10

标签: ios swift concurrency nsoperationqueue dispatch-async

我想了解dispath_queue和NSOperationQueue之间的区别,当我可以将我的代码编写为:

let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
    dispatch_async(queue) { () -> Void in

        let img1 = Downloader.downloadImageWithURL(imageURLs[0])
        dispatch_async(dispatch_get_main_queue(), {
            self.imageView1.image = img1
        })

    }

和as:

queue = NSOperationQueue()

queue.addOperationWithBlock { () -> Void in
    let img4 = Downloader.downloadImageWithURL(imageURLs[3])

    NSOperationQueue.mainQueue().addOperationWithBlock({
        self.imageView4.image = img4
    })

}

那么,这2个区块有什么区别?如果有可能,请为我描述一下

0 个答案:

没有答案