5

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()
    }
})
Arasuvel
  • 2,971
  • 1
  • 25
  • 40
iOSDude
  • 274
  • 2
  • 25

1 Answers1

9

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.

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116