Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

priority and background was deprecated in ios 8

I have an app that is developed with old swift code. now I'm updating it to latest swift syntax. While updating I found difficult in dispatch queue, here it's giving two warnings as global(priority) was deprecated in ios 8 and background was deprecated in ios 8.

DispatchQueue.global(priority: DispatchQueue.GlobalQueuePriority.background).async(execute: { [weak self] in     //Getting warning in this line
    if let strongSelf = self {
        strongSelf.populateOutBoundContacts()
        strongSelf.lookForContactsToPresent()
    }
})
like image 597
iOSDude Avatar asked Aug 17 '17 12:08

iOSDude


1 Answers

The syntax was changed to DispatchQueue.global(qos: DispatchQoS.QoSClass). You don't need to call async(execute), you can directly call async and write the code to be executed in the closure.

DispatchQueue.global(qos: .background).async{ [weak self] in    
    if let strongSelf = self {
        strongSelf.populateOutBoundContacts()
        strongSelf.lookForContactsToPresent()
    }        
}

When updating old code, I strongly suggest going through the documentation of the respective classes and using Xcode's auto completion, it can save you a lot of time when looking for the new syntax/methods.

like image 148
Dávid Pásztor Avatar answered Oct 03 '22 19:10

Dávid Pásztor