Swift 3 warning for dispatch async

asheyla picture asheyla · Sep 30, 2016 · Viewed 14.7k times · Source

I have this code:

DispatchQueue.global(priority: DispatchQueue.GlobalQueuePriority.default).async {
                let url = URL(string: itemImageURL )
                let data = try? Data(contentsOf: url!)
                if data != nil {
                    DispatchQueue.main.async{
                        cell.advImage!.image = UIImage(data: data!)
                    }
                }
            }

I get this warning in Swift 3:

'default' was deprecated in iOS 8.0: Use qos attributes instead

on the first line.

Haven't found yet a solution. Has anybody?

Answer

iPao picture iPao · Sep 30, 2016

try qos: DispatchQoS.QoSClass.default instead of priority: DispatchQueue.GlobalQueuePriority.default

DispatchQueue.global(qos: DispatchQoS.QoSClass.default).async {
            let url = URL(string: itemImageURL )
            let data = try? Data(contentsOf: url!)
            if data != nil {
                DispatchQueue.main.async{
                    cell.advImage!.image = UIImage(data: data!)
                }
            }
        }