Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift 3 warning for dispatch async

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?

like image 731
asheyla Avatar asked Sep 30 '16 11:09

asheyla


2 Answers

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!)
                }
            }
        }
like image 176
iPao Avatar answered Oct 22 '22 05:10

iPao


Instead of using priority parameter:

DispatchQueue.global(priority: DispatchQueue.GlobalQueuePriority.default).async {
 // ...
}

use qos parameter that uses a different enum DispatchQoS.QoSClass.default but you can also use its enum value as just .default:

DispatchQueue.global(qos: .default).async {
 // ...
}

Swift 3 has brought many changes on GCD(Grand Central Dispatch).

like image 5
Wilson Avatar answered Oct 22 '22 04:10

Wilson