I have an array of PHAsset (Let's say, array size is greater than 50,000), and I want to know the file size of each PHAsset. I'm trying it using PHAssetResource.assetResources but it is taking much time. I want to know if there is any faster way of knowing file size. I'm including the code I tried below,
extension PHAsset {
func getSize() -> Double {
let resources = PHAssetResource.assetResources(for: self)
var sizeOnDisk: Int64 = 0
if let resource = resources.first {
let unsignedInt64 = resource.value(forKey: "fileSize") as? CLong
sizeOnDisk = Int64(bitPattern: UInt64(unsignedInt64!))
let fileSize = Double(sizeOnDisk) / (1024.0 * 1024.0)
return fileSize
}
return 0.0
}
}
To be specific this line is taking too much time.
PHAssetResource.assetResources(for: self)