I have a question regarding the last example.
let group = DispatchGroup()
let queue = DispatchQueue.global(qos: .userInitiated)
let base = "https://wolverine.raywenderlich.com/books/con/image-from-rawpixel-id-"
let ids = [ 466881, 466910, 466925, 466931, 466978, 467028, 467032, 467042, 467052 ]
var images: [UIImage] = []
for id in ids {
guard let url = URL(string: "\(base)\(id)-jpeg.jpg") else { continue }
group.enter()
let task = URLSession.shared.dataTask(with: url) { data, _,error in
defer { group.leave()}
if error == nil, let data = data, let image = UIImage(data: data) {
images.append(image)
}
}
task.resume()
}
group.notify(queue: queue) {
let result = images
result[0]
PlaygroundPage.current.finishExecution()
}
What is the use of queue here? I don’t see it being used.
URLSession is running in the background queue. the only reason I see it here as notify need the queue in the signature. Otherwise no real use. I am not running anything on it to be notified.
Thanks for reading