Skip to content

Instantly share code, notes, and snippets.

@robertmryan
Created July 10, 2020 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertmryan/3fa777b853e0c5590d8815b2f313c99c to your computer and use it in GitHub Desktop.
Save robertmryan/3fa777b853e0c5590d8815b2f313c99c to your computer and use it in GitHub Desktop.
private func loadImagesConCurrent() {
let concurrentQueue = DispatchQueue(label: "myConcurrentQueue", qos: .background, attributes: .concurrent)
activity.startAnimating()
let group = DispatchGroup()
for (i, item) in myArray.enumerated() {
group.enter()
concurrentQueue.async { [weak self] in
let fileURL = try! FileManager.default
.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
.appendingPathComponent(item as! String)
guard let image = UIImage(contentsOfFile: fileURL.path) else {
group.leave()
return
}
DispatchQueue.main.async {
self?.imagesCollection[i].image = image
print("loaded")
group.leave()
}
}
}
group.notify(queue: .main) { [weak self] in
self?.activity.startAnimating()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment