Created
July 10, 2020 08:02
-
-
Save robertmryan/3fa777b853e0c5590d8815b2f313c99c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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