I am new on Swift and I am trying to use closure for getting results back from viewcontroller
Here is the example
class MD5Calculator {
static func imageChecksum(imageArray: [UIImage], onCalculated: @escaping () -> [String]){
DispatchQueue.global(qos: .userInitiated).async {
var array: [String] = []
for chosenImage in imageArray {
if let jpegData = UIImageJPEGRepresentation(chosenImage, 80) {
let checksum = jpegData.md5()
let chsum = checksum.toHexString()
array.append(chsum)
}
}
DispatchQueue.main.async {
//return array
}
}
}
}
I want md5 calculation do in background and when its done pass it to viewController.
I created closure but I don't know how to return it. my question is:
How to pass string array with closure
How to call ImageChecksum in view controller